mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread.c: move ppoll wrapper into thread_pthread.c
thread_pthread.c relies on ppoll for rb_sigwait_sleep, so ensure the compatibility wrapper is available for it. [Bug #14950] Reported-by: SHIBATA Hiroshi <hsbt@ruby-lang.org> Reported-by: Greg L <Greg.mpls@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2fa1e2e3c3
commit
3dc7727d22
2 changed files with 42 additions and 43 deletions
54
thread.c
54
thread.c
|
@ -361,49 +361,6 @@ ubf_sigwait(void *ignore)
|
||||||
rb_thread_wakeup_timer_thread(0);
|
rb_thread_wakeup_timer_thread(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_POLL
|
|
||||||
|
|
||||||
/* The same with linux kernel. TODO: make platform independent definition. */
|
|
||||||
#define POLLIN_SET (POLLRDNORM | POLLRDBAND | POLLIN | POLLHUP | POLLERR)
|
|
||||||
#define POLLOUT_SET (POLLWRBAND | POLLWRNORM | POLLOUT | POLLERR)
|
|
||||||
#define POLLEX_SET (POLLPRI)
|
|
||||||
|
|
||||||
#ifndef POLLERR_SET /* defined for FreeBSD for now */
|
|
||||||
# define POLLERR_SET (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef HAVE_PPOLL
|
|
||||||
/* TODO: don't ignore sigmask */
|
|
||||||
static int
|
|
||||||
ruby_ppoll(struct pollfd *fds, nfds_t nfds,
|
|
||||||
const struct timespec *ts, const sigset_t *sigmask)
|
|
||||||
{
|
|
||||||
int timeout_ms;
|
|
||||||
|
|
||||||
if (ts) {
|
|
||||||
int tmp, tmp2;
|
|
||||||
|
|
||||||
if (ts->tv_sec > INT_MAX/1000)
|
|
||||||
timeout_ms = INT_MAX;
|
|
||||||
else {
|
|
||||||
tmp = (int)(ts->tv_sec * 1000);
|
|
||||||
/* round up 1ns to 1ms to avoid excessive wakeups for <1ms sleep */
|
|
||||||
tmp2 = (int)((ts->tv_nsec + 999999L) / (1000L * 1000L));
|
|
||||||
if (INT_MAX - tmp < tmp2)
|
|
||||||
timeout_ms = INT_MAX;
|
|
||||||
else
|
|
||||||
timeout_ms = (int)(tmp + tmp2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
timeout_ms = -1;
|
|
||||||
|
|
||||||
return poll(fds, nfds, timeout_ms);
|
|
||||||
}
|
|
||||||
# define ppoll(fds,nfds,ts,sigmask) ruby_ppoll((fds),(nfds),(ts),(sigmask))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include "thread_win32.c"
|
#include "thread_win32.c"
|
||||||
|
|
||||||
|
@ -4064,6 +4021,17 @@ rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t *
|
||||||
return (int)rb_ensure(do_select, (VALUE)&set, select_set_free, (VALUE)&set);
|
return (int)rb_ensure(do_select, (VALUE)&set, select_set_free, (VALUE)&set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_POLL
|
||||||
|
|
||||||
|
/* The same with linux kernel. TODO: make platform independent definition. */
|
||||||
|
#define POLLIN_SET (POLLRDNORM | POLLRDBAND | POLLIN | POLLHUP | POLLERR)
|
||||||
|
#define POLLOUT_SET (POLLWRBAND | POLLWRNORM | POLLOUT | POLLERR)
|
||||||
|
#define POLLEX_SET (POLLPRI)
|
||||||
|
|
||||||
|
#ifndef POLLERR_SET /* defined for FreeBSD for now */
|
||||||
|
# define POLLERR_SET (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* returns a mask of events
|
* returns a mask of events
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1577,6 +1577,37 @@ rb_sigwait_fd_put(const rb_thread_t *th, int fd)
|
||||||
if (old != th) assert(old == th);
|
if (old != th) assert(old == th);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_PPOLL
|
||||||
|
/* TODO: don't ignore sigmask */
|
||||||
|
static int
|
||||||
|
ruby_ppoll(struct pollfd *fds, nfds_t nfds,
|
||||||
|
const struct timespec *ts, const sigset_t *sigmask)
|
||||||
|
{
|
||||||
|
int timeout_ms;
|
||||||
|
|
||||||
|
if (ts) {
|
||||||
|
int tmp, tmp2;
|
||||||
|
|
||||||
|
if (ts->tv_sec > INT_MAX/1000)
|
||||||
|
timeout_ms = INT_MAX;
|
||||||
|
else {
|
||||||
|
tmp = (int)(ts->tv_sec * 1000);
|
||||||
|
/* round up 1ns to 1ms to avoid excessive wakeups for <1ms sleep */
|
||||||
|
tmp2 = (int)((ts->tv_nsec + 999999L) / (1000L * 1000L));
|
||||||
|
if (INT_MAX - tmp < tmp2)
|
||||||
|
timeout_ms = INT_MAX;
|
||||||
|
else
|
||||||
|
timeout_ms = (int)(tmp + tmp2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
timeout_ms = -1;
|
||||||
|
|
||||||
|
return poll(fds, nfds, timeout_ms);
|
||||||
|
}
|
||||||
|
# define ppoll(fds,nfds,ts,sigmask) ruby_ppoll((fds),(nfds),(ts),(sigmask))
|
||||||
|
#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 struct timespec *ts)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue