diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-16 08:27:56 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-16 08:27:56 +0000 |
commit | 986f11e72ff7dfda0cd2a7f9e7f690929eff0d1f (patch) | |
tree | f7a0cd83b7c9068db2de462a4b2b638e244e988b /thread.c | |
parent | cb2a2c2737be0e965ef3adde46e1eeb80e278fff (diff) |
thread.c (timeout_prepare): common function
I can't seem to reproduce the maybe-uninitialized warning on
gcc 7 or 8 on Debian sid (7.3.0-16 / 8-20180425-1 r259628),
so the guard from r62305 is dropped.
* thread.c (timeout_prepare): hoist out from do_select
(do_select): ditto
(rb_wait_for_single_fd): use timeout_prepare
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 41 |
1 files changed, 19 insertions, 22 deletions
@@ -242,6 +242,21 @@ timeval_for(struct timeval *tv, const struct timespec *ts) return 0; } +static void +timeout_prepare(struct timespec **tsp, + struct timespec *ts, struct timespec *end, + const struct timeval *timeout) +{ + if (timeout) { + getclockofday(end); + timespec_add(end, timespec_for(ts, timeout)); + *tsp = ts; + } + else { + *tsp = 0; + } +} + #if THREAD_DEBUG #ifdef HAVE_VA_ARGS_MACRO void rb_thread_debug(const char *file, int line, const char *fmt, ...); @@ -3830,27 +3845,16 @@ do_select(int n, rb_fdset_t *const readfds, rb_fdset_t *const writefds, rb_fdset_t MAYBE_UNUSED(orig_read); rb_fdset_t MAYBE_UNUSED(orig_write); rb_fdset_t MAYBE_UNUSED(orig_except); - struct timespec end; - struct timespec *tsp = 0; - struct timespec ts -#if defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8) - = {0, 0} -#endif - ; + struct timespec ts, end, *tsp; rb_thread_t *th = GET_THREAD(); + timeout_prepare(&tsp, &ts, &end, timeout); #define do_select_update() \ (restore_fdset(readfds, &orig_read), \ restore_fdset(writefds, &orig_write), \ restore_fdset(exceptfds, &orig_except), \ TRUE) - if (timeout) { - getclockofday(&end); - timespec_add(&end, timespec_for(&ts, timeout)); - tsp = &ts; - } - #define fd_init_copy(f) \ (f##fds) ? rb_fd_init_copy(&orig_##f, f##fds) : rb_fd_no_init(&orig_##f) fd_init_copy(read); @@ -3988,17 +3992,10 @@ rb_wait_for_single_fd(int fd, int events, struct timeval *timeout) { struct pollfd fds; int result = 0, lerrno; - struct timespec ts; - struct timespec end; - struct timespec *tsp = 0; + struct timespec ts, end, *tsp; rb_thread_t *th = GET_THREAD(); - if (timeout) { - getclockofday(&end); - timespec_add(&end, timespec_for(&ts, timeout)); - tsp = &ts; - } - + timeout_prepare(&tsp, &ts, &end, timeout); fds.fd = fd; fds.events = (short)events; |