diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-19 20:14:41 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-19 20:14:41 +0000 |
commit | 98d0ccc86afb6b8e726966f4ed17cfb4e645d307 (patch) | |
tree | c145797f4ffd0862568dcf46c8e98037ab792941 /thread_pthread.c | |
parent | 07ae480dc4d27cc28007dc2b470f669d924d1334 (diff) |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r-- | thread_pthread.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/thread_pthread.c b/thread_pthread.c index 7f57435698..b8778ee608 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1945,24 +1945,25 @@ ruby_ppoll(struct pollfd *fds, nfds_t nfds, #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 sigwait_fd, const struct timespec *ts) * 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_t *rel) 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); |