[前][次][番号順一覧][スレッド一覧]

ruby-changes:52968

From: normal <ko1@a...>
Date: Sat, 20 Oct 2018 05:14:49 +0900 (JST)
Subject: [ruby-changes:52968] normal:r65182 (trunk): rb_sigwait_sleep: change internal API to use rb_hrtime_t

normal	2018-10-20 05:14:41 +0900 (Sat, 20 Oct 2018)

  New Revision: 65182

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65182

  Log:
    rb_sigwait_sleep: change internal API to use rb_hrtime_t
    
    rb_hrtime_t is a more pleasant type to use and this can make
    future changes around sleeping/scheduling easier.

  Modified files:
    trunk/process.c
    trunk/thread_pthread.c
    trunk/thread_win32.c
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 65181)
+++ thread_pthread.c	(revision 65182)
@@ -1945,24 +1945,25 @@ ruby_ppoll(struct pollfd *fds, nfds_t nf https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1945
 #endif
 
 void
-rb_sigwait_sleep(rb_thread_t *th, int sigwait_fd, const struct timespec *ts)
+rb_sigwait_sleep(rb_thread_t *th, int sigwait_fd, const rb_hrtime_t *rel)
 {
     struct pollfd pfd;
+    struct timespec ts;
 
     pfd.fd = sigwait_fd;
     pfd.events = POLLIN;
 
     if (!BUSY_WAIT_SIGNALS && ubf_threads_empty()) {
-        (void)ppoll(&pfd, 1, ts, 0);
+        (void)ppoll(&pfd, 1, rb_hrtime2timespec(&ts, rel), 0);
         check_signals_nogvl(th, sigwait_fd);
     }
     else {
-        rb_hrtime_t rel, end;
+        rb_hrtime_t to = RB_HRTIME_MAX, end;
         int n = 0;
 
-        if (ts) {
-            rel = rb_timespec2hrtime(ts);
-            end = rb_hrtime_add(rb_hrtime_now(), rel);
+        if (rel) {
+            to = *rel;
+            end = rb_hrtime_add(rb_hrtime_now(), to);
         }
         /*
          * tricky: this needs to return on spurious wakeup (no auto-retry).
@@ -1970,16 +1971,15 @@ rb_sigwait_sleep(rb_thread_t *th, int si https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1971
          * wakeups, so we care about the result of consume_communication_pipe
          */
         for (;;) {
-            const rb_hrtime_t *sto = sigwait_timeout(th, sigwait_fd, &rel, &n);
-            struct timespec tmp;
+            const rb_hrtime_t *sto = sigwait_timeout(th, sigwait_fd, &to, &n);
 
             if (n) return;
-            n = ppoll(&pfd, 1, rb_hrtime2timespec(&tmp, sto), 0);
+            n = ppoll(&pfd, 1, rb_hrtime2timespec(&ts, sto), 0);
             if (check_signals_nogvl(th, sigwait_fd))
                 return;
             if (n || (th && RUBY_VM_INTERRUPTED(th->ec)))
                 return;
-            if (ts && hrtime_update_expire(&rel, end))
+            if (rel && hrtime_update_expire(&to, end))
                 return;
         }
     }
@@ -2035,8 +2035,7 @@ native_sleep(rb_thread_t *th, rb_hrtime_ https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L2035
         GVL_UNLOCK_BEGIN(th);
 
         if (!RUBY_VM_INTERRUPTED(th->ec)) {
-            struct timespec ts;
-            rb_sigwait_sleep(th, sigwait_fd, rb_hrtime2timespec(&ts, rel));
+            rb_sigwait_sleep(th, sigwait_fd, rel);
         }
         else {
             check_signals_nogvl(th, sigwait_fd);
Index: thread_win32.c
===================================================================
--- thread_win32.c	(revision 65181)
+++ thread_win32.c	(revision 65182)
@@ -793,9 +793,9 @@ rb_sigwait_fd_put(rb_thread_t *th, int f https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L793
     rb_bug("not implemented, should not be called");
 }
 
-NORETURN(void rb_sigwait_sleep(const rb_thread_t *, int, const struct timespec *));
+NORETURN(void rb_sigwait_sleep(const rb_thread_t *, int, const rb_hrtime_t *));
 void
-rb_sigwait_sleep(const rb_thread_t *th, int fd, const struct timespec *ts)
+rb_sigwait_sleep(const rb_thread_t *th, int fd, const rb_hrtime_t *rel)
 {
     rb_bug("not implemented, should not be called");
 }
Index: process.c
===================================================================
--- process.c	(revision 65181)
+++ process.c	(revision 65182)
@@ -17,6 +17,7 @@ https://github.com/ruby/ruby/blob/trunk/process.c#L17
 #include "ruby/thread.h"
 #include "ruby/util.h"
 #include "vm_core.h"
+#include "hrtime.h"
 
 #include <stdio.h>
 #include <errno.h>
@@ -931,7 +932,7 @@ void rb_native_mutex_unlock(rb_nativethr https://github.com/ruby/ruby/blob/trunk/process.c#L932
 void rb_native_cond_signal(rb_nativethread_cond_t *);
 void rb_native_cond_wait(rb_nativethread_cond_t *, rb_nativethread_lock_t *);
 int rb_sigwait_fd_get(const rb_thread_t *);
-void rb_sigwait_sleep(const rb_thread_t *, int fd, const struct timespec *);
+void rb_sigwait_sleep(const rb_thread_t *, int fd, const rb_hrtime_t *);
 void rb_sigwait_fd_put(const rb_thread_t *, int fd);
 void rb_thread_sleep_interruptible(void);
 
@@ -1026,11 +1027,11 @@ waitpid_state_init(struct waitpid_state https://github.com/ruby/ruby/blob/trunk/process.c#L1027
     w->options = options;
 }
 
-static const struct timespec *
+static const rb_hrtime_t *
 sigwait_sleep_time(void)
 {
     if (SIGCHLD_LOSSY) {
-        static const struct timespec busy_wait = { 0, 100000000 };
+        static const rb_hrtime_t busy_wait = 100 * RB_HRTIME_PER_MSEC;
 
         return &busy_wait;
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]