aboutsummaryrefslogtreecommitdiffstats
path: root/thread_pthread.c
diff options
context:
space:
mode:
authorngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-16 13:06:13 +0000
committerngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-16 13:06:13 +0000
commit1cc39351268ceda53f63c8bafe43dfb40214b720 (patch)
tree0c55e26fb6b4a592dc09521917cbd4f5e525a25c /thread_pthread.c
parent0d343aff7e2efdecc91e9f2554733fdf6ad9025c (diff)
downloadruby-1cc39351268ceda53f63c8bafe43dfb40214b720.tar.gz
* process.c (redirect_dup2): when the new FD of dup2() coflicts
with one of the timer thread FDs, the internal FD is diverted. [Bug #11336] [ruby-core:69886] [Bug #11350] [ruby-core:69961] * process.c (dup2_with_divert): new function for the above purpose. * thread_pthread.c (rb_divert_reserved_fd): new function for diverting reserved FD. If the given FD is the same as one of the reserved FDs, the reserved FD number is internally changed. It returns -1 when error. Otherwise, returns 0. It also returns 0 if there is no need to change reserved FD number. * thread_win32.c (rb_divert_reserved_fd): always returns 0 because of no reserved FDs. * internal.h (rb_divert_reserved_fd): prototype declaration. It is Ruby internal use only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 71edee18b0..26fe9ffddf 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1707,6 +1707,29 @@ rb_reserved_fd_p(int fd)
#endif
}
+int
+rb_divert_reserved_fd(int fd)
+{
+#if USE_SLEEPY_TIMER_THREAD
+ int *ptr;
+ int newfd;
+
+ if ((fd == *(ptr = &(timer_thread_pipe.normal[0])) ||
+ fd == *(ptr = &(timer_thread_pipe.normal[1])) ||
+ fd == *(ptr = &(timer_thread_pipe.low[0])) ||
+ fd == *(ptr = &(timer_thread_pipe.low[1]))) &&
+ timer_thread_pipe.owner_process == getpid()) { /* async-signal-safe */
+ newfd = rb_cloexec_dup(fd); /* async-signal-safe if no error */
+ if (newfd == -1) return -1;
+ rb_update_max_fd(newfd); /* async-signal-safe if no error */
+ /* set_nonblock(newfd); */ /* async-signal-safe if no error */
+ *ptr = newfd;
+ rb_thread_wakeup_timer_thread_low(); /* async-signal-safe? */
+ }
+#endif
+ return 0;
+}
+
rb_nativethread_id_t
rb_nativethread_self(void)
{