From 16d4733ee49d749e4dad3de896a3f02e0573eeff Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 28 Nov 2010 12:46:27 +0000 Subject: * thread_pthread.c (thread_start_func_1): initialize native thread data immediately before starting. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_pthread.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'thread_pthread.c') diff --git a/thread_pthread.c b/thread_pthread.c index 8a10d3a217..797399b97e 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -324,6 +324,8 @@ ruby_thread_set_native(rb_thread_t *th) return pthread_setspecific(ruby_native_thread_key, th) == 0; } +static void native_thread_init(rb_thread_t *th); + void Init_native_thread(void) { @@ -331,11 +333,17 @@ Init_native_thread(void) pthread_key_create(&ruby_native_thread_key, NULL); th->thread_id = pthread_self(); + native_thread_init(th); + native_mutex_initialize(&signal_thread_list_lock); + posix_signal(SIGVTALRM, null_func); +} + +static void +native_thread_init(rb_thread_t *th) +{ native_cond_initialize(&th->native_thread_data.sleep_cond); native_cond_initialize(&th->native_thread_data.gvl_cond); ruby_thread_set_native(th); - native_mutex_initialize(&signal_thread_list_lock); - posix_signal(SIGVTALRM, null_func); } static void @@ -519,6 +527,7 @@ thread_start_func_1(void *th_ptr) #ifndef __CYGWIN__ native_thread_init_stack(th); #endif + native_thread_init(th); /* run */ thread_start_func_2(th, &stack_start, rb_ia64_bsp()); } @@ -679,10 +688,6 @@ native_thread_create(rb_thread_t *th) err = pthread_create(&th->thread_id, &attr, thread_start_func_1, th); thread_debug("create: %p (%d)", (void *)th, err); CHECK_ERR(pthread_attr_destroy(&attr)); - - if (!err) { - pthread_cond_init(&th->native_thread_data.sleep_cond, 0); - } } return err; } -- cgit v1.2.3