From cbf33c59ded17f32783954a2226df63af9089504 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Tue, 8 Jun 2010 03:58:37 +0000 Subject: merge revision(s) 26371,26373,26374,26972: * eval.c (thread_timer, rb_thread_stop_timer): check the timing of stopping timer. patch from KOSAKI Motohiro * eval.c (rb_thread_start_timer): NetBSD5 seems to be hung when calling pthread_create() from pthread_atfork()'s parent handler. * io.c (pipe_open): workaround for NetBSD5. stop timer thread before fork(), and start it if needed. * process.c (rb_f_fork, rb_f_system): ditto. fixed [ruby-dev:40074] jp.fujitsu.com> via IRC. fork(), and restart it after fork() on parent, and on child if needed. these changes are tested by naruse. fixed [ruby-dev:40074] * io.c, eval.c, process.c: add linux to r26371's condition. patched by Motohiro KOSAKI [ruby-core:28151] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@28203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- eval.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 5c28881474..94a702072c 100644 --- a/eval.c +++ b/eval.c @@ -12292,6 +12292,8 @@ static struct timer_thread { pthread_t thread; } time_thread = {PTHREAD_COND_INITIALIZER, PTHREAD_MUTEX_INITIALIZER}; +static int timer_stopping; + #define safe_mutex_lock(lock) \ pthread_mutex_lock(lock); \ pthread_cleanup_push((void (*)_((void *)))pthread_mutex_unlock, lock) @@ -12316,6 +12318,9 @@ thread_timer(dummy) #define WAIT_FOR_10MS() \ pthread_cond_timedwait(&running->cond, &running->lock, get_ts(&to, PER_NANO/100)) while ((err = WAIT_FOR_10MS()) == EINTR || err == ETIMEDOUT) { + if (timer_stopping) + break; + if (!rb_thread_critical) { rb_thread_pending = 1; if (rb_trap_immediate) { @@ -12343,7 +12348,9 @@ rb_thread_start_timer() safe_mutex_lock(&time_thread.lock); if (pthread_create(&time_thread.thread, 0, thread_timer, args) == 0) { thread_init = 1; +#if !defined(__NetBSD__) && !defined(__APPLE__) && !defined(linux) pthread_atfork(0, 0, rb_thread_stop_timer); +#endif pthread_cond_wait(&start, &time_thread.lock); } pthread_cleanup_pop(1); @@ -12354,10 +12361,12 @@ rb_thread_stop_timer() { if (!thread_init) return; safe_mutex_lock(&time_thread.lock); + timer_stopping = 1; pthread_cond_signal(&time_thread.cond); thread_init = 0; pthread_cleanup_pop(1); pthread_join(time_thread.thread, NULL); + timer_stopping = 0; } #elif defined(HAVE_SETITIMER) static void -- cgit v1.2.3