From e2b10b6d131425c395c5fe286ce6fd55d46f7c51 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 11 Jun 2014 08:37:44 +0000 Subject: thread_pthread.c: timer thread flag * thread_pthread.c (timer_thread): add a flag to tell timer thread is created, since 0 may be a valid value as pthread_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_win32.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'thread_win32.c') diff --git a/thread_win32.c b/thread_win32.c index feadede50d..a0b26e3d4a 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -692,14 +692,17 @@ ubf_handle(void *ptr) w32_set_event(th->native_thread_data.interrupt_event); } -static HANDLE timer_thread_id = 0; -static HANDLE timer_thread_lock; +static struct { + HANDLE id; + HANDLE lock; +} timer_thread; +#define TIMER_THREAD_CREATED_P() (timer_thread.id != 0) static unsigned long __stdcall timer_thread_func(void *dummy) { thread_debug("timer_thread\n"); - while (WaitForSingleObject(timer_thread_lock, TIME_QUANTUM_USEC/1000) == + while (WaitForSingleObject(timer_thread.lock, TIME_QUANTUM_USEC/1000) == WAIT_TIMEOUT) { timer_thread_function(dummy); } @@ -716,13 +719,13 @@ rb_thread_wakeup_timer_thread(void) static void rb_thread_create_timer_thread(void) { - if (timer_thread_id == 0) { - if (!timer_thread_lock) { - timer_thread_lock = CreateEvent(0, TRUE, FALSE, 0); + if (timer_thread.id == 0) { + if (!timer_thread.lock) { + timer_thread.lock = CreateEvent(0, TRUE, FALSE, 0); } - timer_thread_id = w32_create_thread(1024 + (THREAD_DEBUG ? BUFSIZ : 0), + timer_thread.id = w32_create_thread(1024 + (THREAD_DEBUG ? BUFSIZ : 0), timer_thread_func, 0); - w32_resume_thread(timer_thread_id); + w32_resume_thread(timer_thread.id); } } @@ -731,10 +734,10 @@ native_stop_timer_thread(int close_anyway) { int stopped = --system_working <= 0; if (stopped) { - SetEvent(timer_thread_lock); - native_thread_join(timer_thread_id); - CloseHandle(timer_thread_lock); - timer_thread_lock = 0; + SetEvent(timer_thread.lock); + native_thread_join(timer_thread.id); + CloseHandle(timer_thread.lock); + timer_thread.lock = 0; } return stopped; } @@ -742,9 +745,9 @@ native_stop_timer_thread(int close_anyway) static void native_reset_timer_thread(void) { - if (timer_thread_id) { - CloseHandle(timer_thread_id); - timer_thread_id = 0; + if (timer_thread.id) { + CloseHandle(timer_thread.id); + timer_thread.id = 0; } } -- cgit v1.2.3