aboutsummaryrefslogtreecommitdiffstats
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-30 00:31:08 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-30 00:31:08 +0000
commit8f24f049dd8953f0fb65748bed33f6391b951048 (patch)
tree38b3d01eba8a6fcb6e06c0fe0c8540f6ef7809f8 /thread_pthread.c
parentc3bf0f561b83f181763cb8e582c08c94498791f6 (diff)
downloadruby-8f24f049dd8953f0fb65748bed33f6391b951048.tar.gz
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
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index b0b40ed5df..c1cfe531f0 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1577,6 +1577,37 @@ rb_sigwait_fd_put(const rb_thread_t *th, int fd)
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
rb_sigwait_sleep(rb_thread_t *th, int sigwait_fd, const struct timespec *ts)
{