From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 20C8321845 for ; Tue, 1 May 2018 08:08:45 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [WIP v2 1/4] thread.c (timeout_prepare): common function Date: Tue, 1 May 2018 08:08:41 +0000 Message-Id: <20180501080844.22751-2-e@80x24.org> In-Reply-To: <20180501080844.22751-1-e@80x24.org> References: <20180501080844.22751-1-e@80x24.org> List-Id: 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 --- thread.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/thread.c b/thread.c index 7ca6625d7c..ad216f5f0c 100644 --- a/thread.c +++ b/thread.c @@ -232,6 +232,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, ...); @@ -3809,27 +3824,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), \ update_timespec(tsp, &end)) - 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); @@ -3960,17 +3964,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; -- EW