From 5732566f4d9a026fef3904f3237a9f7255ba91f2 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 6 Nov 2008 13:21:26 +0000 Subject: * thread.c (rb_thread_stop_timer_thread): terminates timer thread immediately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_win32.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'thread_win32.c') diff --git a/thread_win32.c b/thread_win32.c index 46780d8ff4..5d6bf9e4bf 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -451,11 +451,26 @@ native_thread_destroy(rb_thread_t *th) w32_close_handle(intr); } +static void * +get_stack_info(const void *ptr, size_t *maxsize) +{ + MEMORY_BASIC_INFORMATION mi; + DWORD size; + DWORD space; + + if (!VirtualQuery(ptr, &mi, sizeof(mi))) return 0; + size = (char *)mi.BaseAddress - (char *)mi.AllocationBase; + space = size / 5; + if (space > 1024*1024) space = 1024*1024; + *maxsize = size - space; + return (VALUE *)mi.BaseAddress - 1; +} + static unsigned long _stdcall thread_start_func_1(void *th_ptr) { rb_thread_t *th = th_ptr; - VALUE stack_start; + VALUE *stack_start; volatile HANDLE thread_id = th->thread_id; native_thread_init_stack(th); @@ -464,7 +479,9 @@ 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); + + stack_start = get_stack_info(&stack_start, &th->machine_stack_maxsize); + thread_start_func_2(th, stack_start, rb_ia64_bsp()); w32_close_handle(thread_id); thread_debug("thread deleted (th: %p)\n", th); @@ -531,27 +548,33 @@ 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); } } +#define native_stop_timer_thread() (CloseHandle(timer_thread_lock), timer_thread_lock = 0) + #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */ -- cgit v1.2.3