From 2015069a204e8ba13709f94aed5e4341ea297728 Mon Sep 17 00:00:00 2001 From: yugui Date: Sun, 30 Nov 2008 09:22:31 +0000 Subject: * thread.c, thread_pthread.c, thread_win32.c: merges nobu's commits - r20117, r20123, r20124, r20127, r20132-r20134, r20138, r20140, r20141 and r20160 - from trunk into ruby_1_9_1. * thread_pthread.c (thread_timer): checks working flags again. * thread_pthread.c (rb_thread_create_timer_thread): do not wait never coming signal if failed to create tiemr thread. * thread_pthread.c (native_cond_timedwait): returns error code. * thread_pthread.c (thread_timer, rb_thread_create_timer_thread): handshakes properly. * thread_pthread.c (thread_timer): initializes mutex each time. * thread_win32.c (thread_start_func_1): use already gotten stack info. * thread.c (thread_timer): pthread_cond_timedwait returns ETIMEDOUT when timed out. * thread_pthread.c (thread_timer): uses pthread_cond_timedwait always instead of pthread_kill. * thread.c (thread_timer): uses timedwait on cygwin. * thread.c (rb_thread_stop_timer_thread): terminates timer thread immediately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@20407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_win32.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'thread_win32.c') diff --git a/thread_win32.c b/thread_win32.c index 46780d8ff4..0befbff4ae 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -455,7 +455,6 @@ static unsigned long _stdcall thread_start_func_1(void *th_ptr) { rb_thread_t *th = th_ptr; - VALUE stack_start; volatile HANDLE thread_id = th->thread_id; native_thread_init_stack(th); @@ -464,7 +463,8 @@ thread_start_func_1(void *th_ptr) /* run */ thread_debug("thread created (th: %p, thid: %p, event: %p)\n", th, th->thread_id, th->native_thread_data.interrupt_event); - thread_start_func_2(th, &stack_start, 0); + + thread_start_func_2(th, th->machine_stack_start, rb_ia64_bsp()); w32_close_handle(thread_id); thread_debug("thread deleted (th: %p)\n", th); @@ -531,27 +531,42 @@ ubf_handle(void *ptr) } static HANDLE timer_thread_id = 0; +static HANDLE timer_thread_lock; static unsigned long _stdcall timer_thread_func(void *dummy) { thread_debug("timer_thread\n"); - while (system_working) { - Sleep(WIN32_WAIT_TIMEOUT); + while (WaitForSingleObject(timer_thread_lock, WIN32_WAIT_TIMEOUT) == + WAIT_TIMEOUT) { timer_thread_function(dummy); } thread_debug("timer killed\n"); return 0; } -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); + } timer_thread_id = w32_create_thread(1024 + (THREAD_DEBUG ? BUFSIZ : 0), - timer_thread_func, GET_VM()); + timer_thread_func, 0); w32_resume_thread(timer_thread_id); } } +static int +native_stop_timer_thread(void) +{ + int stopped = --system_working <= 0; + if (stopped) { + CloseHandle(timer_thread_lock); + timer_thread_lock = 0; + } + return stopped; +} + #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */ -- cgit v1.2.3