From 0f16eb809cc692061e9e64797aa5ec71466b60b0 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 15 Dec 2003 16:14:49 +0000 Subject: * eval.c (catch_timer): check rb_thread_crtical in main native thread. * eval.c (thread_timer): just sends signals periodically, to prevent main native thread from receiving them in critical section. [ruby-core:01959] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@5195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ eval.c | 50 +++++++++++++++++--------------------------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index 661a0069a..1d49d477c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Dec 16 01:14:44 2003 Nobuyoshi Nakada + + * eval.c (catch_timer): check rb_thread_crtical in main native + thread. + + * eval.c (thread_timer): just sends signals periodically, to + prevent main native thread from receiving them in critical + section. [ruby-core:01959] + Mon Dec 15 13:32:22 2003 Nobuyoshi Nakada * dir.c (check_dirname): check string safety and remove extraneous diff --git a/eval.c b/eval.c index 1a591aea7..a793ae64b 100644 --- a/eval.c +++ b/eval.c @@ -9498,9 +9498,7 @@ static int thread_init = 0; # define ruby_signal(x,y) signal((x), (y)) #endif -#if defined(PTHREAD_TIMER) -static pthread_t time_thread; - +#if defined(PTHREAD_TIMER) || defined(HAVE_SETITIMER) static void catch_timer(sig) int sig; @@ -9508,9 +9506,17 @@ catch_timer(sig) #if !defined(POSIX_SIGNAL) && !defined(BSD_SIGNAL) signal(sig, catch_timer); #endif - rb_thread_schedule(); + if (!rb_thread_critical) { + if (rb_trap_immediate) { + rb_thread_schedule(); + } + else rb_thread_pending = 1; + } } +#ifdef PTHREAD_TIMER +static pthread_t time_thread; + static void* thread_timer(dummy) void *dummy; @@ -9518,17 +9524,10 @@ thread_timer(dummy) struct timespec req, rem; for (;;) { - if (!rb_thread_critical) { - if (rb_trap_immediate) { - pthread_kill(ruby_thid, SIGVTALRM); - } - else { - rb_thread_pending = 1; - } - req.tv_sec = 0; - req.tv_nsec = 10000000; - nanosleep(&req, &rem); - } + req.tv_sec = 0; + req.tv_nsec = 10000000; + nanosleep(&req, &rem); + pthread_kill(ruby_thid, SIGVTALRM); } } @@ -9541,23 +9540,7 @@ void rb_thread_stop_timer() { } -#elif defined(HAVE_SETITIMER) - -static void -catch_timer(sig) - int sig; -{ -#if !defined(POSIX_SIGNAL) && !defined(BSD_SIGNAL) - signal(sig, catch_timer); -#endif - if (!rb_thread_critical) { - if (rb_trap_immediate) { - rb_thread_schedule(); - } - else rb_thread_pending = 1; - } -} - +#else /* HAVE_SETITIMER */ void rb_thread_start_timer() { @@ -9581,7 +9564,8 @@ rb_thread_stop_timer() tval.it_value = tval.it_interval; setitimer(ITIMER_VIRTUAL, &tval, NULL); } -#else +#endif +#else /* !(PTHREAD_TIMER || HAVE_SETITIMER) */ int rb_thread_tick = THREAD_TICK; #endif -- cgit