From fc3c60f6081d85f6274986a7a08b59db1515fcb5 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 14 Jun 2008 02:59:19 +0000 Subject: * gc.h (STACK_UPPER): moved from gc.c * thread.c, thread_{pthread,win32}.c (ruby_init_stack, ruby_thread_init_stack): moved stack initialization from gc.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_win32.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'thread_win32.c') diff --git a/thread_win32.c b/thread_win32.c index 2e05524ab2..d1d0886f43 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -424,6 +424,32 @@ native_cond_destroy(rb_thread_cond_t *cond) /* */ } +void +ruby_init_stack(VALUE *addr) +{ +} + +#define CHECK_ERR(expr) \ + {if (!(expr)) {rb_bug("err: %lu - %s", GetLastError(), #expr);}} + +static void +native_thread_init_stack(rb_thread_t *th) +{ + MEMORY_BASIC_INFORMATION mi; + char *base, *end; + DWORD size, space; + + CHECK_ERR(VirtualQuery(&mi, &mi, sizeof(mi))); + base = mi.AllocationBase; + end = mi.BaseAddress; + end += mi.RegionSize; + size = end - base; + space = size / 5; + if (space > 1024*1024) space = 1024*1024; + th->machine_stack_start = (VALUE *)end - 1; + th->machine_stack_maxsize = size - space; +} + static void native_thread_destroy(rb_thread_t *th) { @@ -441,6 +467,7 @@ thread_start_func_1(void *th_ptr) VALUE stack_start; volatile HANDLE thread_id = th->thread_id; + native_thread_init_stack(th); th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0); /* run */ @@ -453,16 +480,12 @@ thread_start_func_1(void *th_ptr) return 0; } -extern size_t rb_gc_stack_maxsize; - static int native_thread_create(rb_thread_t *th) { size_t stack_size = 4 * 1024; /* 4KB */ th->thread_id = w32_create_thread(stack_size, thread_start_func_1, th); - th->machine_stack_maxsize = rb_gc_stack_maxsize; /* not tested. */ - if ((th->thread_id) == 0) { st_delete_wrap(th->vm->living_threads, th->self); rb_raise(rb_eThreadError, "can't create Thread (%d)", errno); -- cgit v1.2.3