dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [WIP v2 1/4] thread.c (timeout_prepare): common function
Date: Tue,  1 May 2018 08:08:41 +0000	[thread overview]
Message-ID: <20180501080844.22751-2-e@80x24.org> (raw)
In-Reply-To: <20180501080844.22751-1-e@80x24.org>

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


  reply	other threads:[~2018-05-01  8:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-01  8:08 [WIP v2 0/4] sleepy GC Eric Wong
2018-05-01  8:08 ` Eric Wong [this message]
2018-05-01  8:08 ` [WIP v2 2/4] gc: rb_wait_for_single_fd performs GC if idle (Linux) Eric Wong
2018-05-01  8:08 ` [WIP v2 3/4] thread.c (do_select): perform GC if idle Eric Wong
2018-05-01  8:08 ` [WIP v2 4/4] thread.c: native_sleep callers may perform GC Eric Wong
2018-05-02  4:42   ` [PATCH 5/4] thread_sync.c (mutex_lock): add missing else Eric Wong
2018-05-02  4:52 ` [PATCH 6/4] gc.c: allow disabling sleepy GC Eric Wong
2018-05-02  4:57 ` [PATCH] benchmark: add benchmarks for " Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180501080844.22751-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).