diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-05-22 22:32:16 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-05-22 22:32:16 +0000 |
commit | 8d44e350f902986124f58d7786da86dfca1bc0d5 (patch) | |
tree | 13ce0332da855996fc66ba8dd2270072ba9e40b3 /eval.c | |
parent | 2faba093569c034989b27f2380e67311670d225f (diff) |
* process.c (proc_exec_v): terminate timer thread in advance.
[ruby-dev:30581], Thanks H. Holon.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@12343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -11747,21 +11747,31 @@ catch_timer(sig) /* cause EINTR */ } +static int time_thread_alive_p = 0; static pthread_t time_thread; static void* thread_timer(dummy) void *dummy; { +#ifdef _THREAD_SAFE +#define test_cancel() pthread_testcancel() +#else +#define test_cancel() /* void */ +#endif + for (;;) { #ifdef HAVE_NANOSLEEP struct timespec req, rem; + test_cancel(); req.tv_sec = 0; req.tv_nsec = 10000000; nanosleep(&req, &rem); #else struct timeval tv; + + test_cancel(); tv.tv_sec = 0; tv.tv_usec = 10000; select(0, NULL, NULL, NULL, &tv); @@ -11773,6 +11783,7 @@ thread_timer(dummy) } } } +#undef test_cancel } void @@ -11784,6 +11795,20 @@ void rb_thread_stop_timer() { } + +void +rb_thread_cancel_timer() +{ +#ifdef _THREAD_SAFE + if( time_thread_alive_p ) + { + pthread_cancel( time_thread ); + pthread_join( time_thread, NULL ); + time_thread_alive_p = 0; + } + thread_init = 0; +#endif +} #elif defined(HAVE_SETITIMER) static void catch_timer(sig) @@ -11821,6 +11846,12 @@ rb_thread_stop_timer() tval.it_value = tval.it_interval; setitimer(ITIMER_VIRTUAL, &tval, NULL); } + +void +rb_thread_cancel_timer() +{ +} + #else /* !(_THREAD_SAFE || HAVE_SETITIMER) */ int rb_thread_tick = THREAD_TICK; #endif @@ -11853,6 +11884,7 @@ rb_thread_start_0(fn, arg, th) #ifdef _THREAD_SAFE pthread_create(&time_thread, 0, thread_timer, 0); + time_thread_alive_p = 1; #else rb_thread_start_timer(); #endif |