mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
07ae480dc4
commit
98d0ccc86a
3 changed files with 17 additions and 17 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include "ruby/thread.h"
|
#include "ruby/thread.h"
|
||||||
#include "ruby/util.h"
|
#include "ruby/util.h"
|
||||||
#include "vm_core.h"
|
#include "vm_core.h"
|
||||||
|
#include "hrtime.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -931,7 +932,7 @@ void rb_native_mutex_unlock(rb_nativethread_lock_t *);
|
||||||
void rb_native_cond_signal(rb_nativethread_cond_t *);
|
void rb_native_cond_signal(rb_nativethread_cond_t *);
|
||||||
void rb_native_cond_wait(rb_nativethread_cond_t *, rb_nativethread_lock_t *);
|
void rb_native_cond_wait(rb_nativethread_cond_t *, rb_nativethread_lock_t *);
|
||||||
int rb_sigwait_fd_get(const rb_thread_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_sigwait_fd_put(const rb_thread_t *, int fd);
|
||||||
void rb_thread_sleep_interruptible(void);
|
void rb_thread_sleep_interruptible(void);
|
||||||
|
|
||||||
|
@ -1026,11 +1027,11 @@ waitpid_state_init(struct waitpid_state *w, rb_pid_t pid, int options)
|
||||||
w->options = options;
|
w->options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct timespec *
|
static const rb_hrtime_t *
|
||||||
sigwait_sleep_time(void)
|
sigwait_sleep_time(void)
|
||||||
{
|
{
|
||||||
if (SIGCHLD_LOSSY) {
|
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;
|
return &busy_wait;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1945,24 +1945,25 @@ ruby_ppoll(struct pollfd *fds, nfds_t nfds,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
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 pollfd pfd;
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
pfd.fd = sigwait_fd;
|
pfd.fd = sigwait_fd;
|
||||||
pfd.events = POLLIN;
|
pfd.events = POLLIN;
|
||||||
|
|
||||||
if (!BUSY_WAIT_SIGNALS && ubf_threads_empty()) {
|
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);
|
check_signals_nogvl(th, sigwait_fd);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_hrtime_t rel, end;
|
rb_hrtime_t to = RB_HRTIME_MAX, end;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
if (ts) {
|
if (rel) {
|
||||||
rel = rb_timespec2hrtime(ts);
|
to = *rel;
|
||||||
end = rb_hrtime_add(rb_hrtime_now(), rel);
|
end = rb_hrtime_add(rb_hrtime_now(), to);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* tricky: this needs to return on spurious wakeup (no auto-retry).
|
* 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
|
* wakeups, so we care about the result of consume_communication_pipe
|
||||||
*/
|
*/
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const rb_hrtime_t *sto = sigwait_timeout(th, sigwait_fd, &rel, &n);
|
const rb_hrtime_t *sto = sigwait_timeout(th, sigwait_fd, &to, &n);
|
||||||
struct timespec tmp;
|
|
||||||
|
|
||||||
if (n) return;
|
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))
|
if (check_signals_nogvl(th, sigwait_fd))
|
||||||
return;
|
return;
|
||||||
if (n || (th && RUBY_VM_INTERRUPTED(th->ec)))
|
if (n || (th && RUBY_VM_INTERRUPTED(th->ec)))
|
||||||
return;
|
return;
|
||||||
if (ts && hrtime_update_expire(&rel, end))
|
if (rel && hrtime_update_expire(&to, end))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2035,8 +2035,7 @@ native_sleep(rb_thread_t *th, rb_hrtime_t *rel)
|
||||||
GVL_UNLOCK_BEGIN(th);
|
GVL_UNLOCK_BEGIN(th);
|
||||||
|
|
||||||
if (!RUBY_VM_INTERRUPTED(th->ec)) {
|
if (!RUBY_VM_INTERRUPTED(th->ec)) {
|
||||||
struct timespec ts;
|
rb_sigwait_sleep(th, sigwait_fd, rel);
|
||||||
rb_sigwait_sleep(th, sigwait_fd, rb_hrtime2timespec(&ts, rel));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
check_signals_nogvl(th, sigwait_fd);
|
check_signals_nogvl(th, sigwait_fd);
|
||||||
|
|
|
@ -793,9 +793,9 @@ rb_sigwait_fd_put(rb_thread_t *th, int fd)
|
||||||
rb_bug("not implemented, should not be called");
|
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
|
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");
|
rb_bug("not implemented, should not be called");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue