diff options
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | pthread_start.c | 4 | ||||
-rw-r--r-- | pthread_stop_world.c | 22 | ||||
-rw-r--r-- | pthread_support.c | 43 | ||||
-rw-r--r-- | win32_threads.c | 37 |
5 files changed, 79 insertions, 48 deletions
@@ -1,5 +1,26 @@ 2011-05-10 Ivan Maidanski <ivmai@mail.ru> + * pthread_start.c (GC_start_rtn_prepare_thread): Change return + type to GC_thread. + * pthread_start.c (GC_inner_start_routine): Pass the current + thread descriptor to pthread_cleanup_push (same as in + win32_threads.c). + * pthread_stop_world.c (GC_push_all_stacks): Rename "me" local + variable to "self". + * win32_threads.c (GC_push_all_stacks): Ditto. + * pthread_stop_world.c (GC_suspend_all, GC_start_world): Rename + "my_thread" local variable to "self". + * pthread_support.c (GC_unregister_my_thread_inner): New static + function. + * pthread_support.c (GC_unregister_my_thread, + GC_thread_exit_proc): Use GC_unregister_my_thread_inner. + * win32_threads.c (GC_register_my_thread, GC_unregister_my_thread, + GC_do_blocking_inner): Rename "t" local variable to "thread_id". + * win32_threads.c (GC_wait_marker, GC_notify_all_marker): Rename + "id" local variable to "thread_id". + +2011-05-10 Ivan Maidanski <ivmai@mail.ru> + * pthread_support.c (GC_unregister_my_thread): Call pthread_self only once. * win32_threads.c (GC_pthread_start_inner): Ditto. diff --git a/pthread_start.c b/pthread_start.c index 48c2d95a..c3a01c41 100644 --- a/pthread_start.c +++ b/pthread_start.c @@ -41,7 +41,7 @@ #include <pthread.h> #include <sched.h> -GC_INNER void * GC_start_rtn_prepare_thread(void *(**pstart)(void *), +GC_INNER GC_thread GC_start_rtn_prepare_thread(void *(**pstart)(void *), void **pstart_arg, struct GC_stack_base *sb, void *arg); GC_INNER void GC_thread_exit_proc(void *arg); @@ -56,7 +56,7 @@ void * GC_CALLBACK GC_inner_start_routine(struct GC_stack_base *sb, void *arg) GC_thread me = GC_start_rtn_prepare_thread(&start, &start_arg, sb, arg); # ifndef NACL - pthread_cleanup_push(GC_thread_exit_proc, 0); + pthread_cleanup_push(GC_thread_exit_proc, me); # endif result = (*start)(start_arg); # ifdef DEBUG_THREADS diff --git a/pthread_stop_world.c b/pthread_stop_world.c index d7680e42..feb70a3b 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -297,18 +297,18 @@ GC_INNER void GC_push_all_stacks(void) ptr_t lo, hi; /* On IA64, we also need to scan the register backing store. */ IF_IA64(ptr_t bs_lo; ptr_t bs_hi;) - pthread_t me = pthread_self(); + pthread_t self = pthread_self(); word total_size = 0; if (!GC_thr_initialized) GC_thr_init(); # ifdef DEBUG_THREADS - GC_log_printf("Pushing stacks from thread 0x%x\n", (unsigned)me); + GC_log_printf("Pushing stacks from thread 0x%x\n", (unsigned)self); # endif for (i = 0; i < THREAD_TABLE_SZ; i++) { for (p = GC_threads[i]; p != 0; p = p -> next) { if (p -> flags & FINISHED) continue; ++nthreads; - if (THREAD_EQUAL(p -> id, me)) { + if (THREAD_EQUAL(p -> id, self)) { GC_ASSERT(!p->thread_blocked); # ifdef SPARC lo = (ptr_t)GC_save_regs_in_stack(); @@ -351,10 +351,10 @@ GC_INNER void GC_push_all_stacks(void) GC_log_printf("Reg stack for thread 0x%x = [%p,%p)\n", (unsigned)p -> id, bs_lo, bs_hi); # endif - /* FIXME: This (if p->id==me) may add an unbounded number of */ - /* entries, and hence overflow the mark stack, which is bad. */ + /* FIXME: This (if p->id==self) may add an unbounded number of */ + /* entries, and hence overflow the mark stack, which is bad. */ GC_push_all_register_sections(bs_lo, bs_hi, - THREAD_EQUAL(p -> id, me), + THREAD_EQUAL(p -> id, self), p -> traced_stack_sect); total_size += bs_hi - bs_lo; /* bs_lo <= bs_hi */ # endif @@ -406,15 +406,15 @@ STATIC int GC_suspend_all(void) # ifndef GC_OPENBSD_THREADS int result; # endif - pthread_t my_thread = pthread_self(); + pthread_t self = pthread_self(); # ifdef DEBUG_THREADS - GC_stopping_thread = my_thread; + GC_stopping_thread = self; GC_stopping_pid = getpid(); # endif for (i = 0; i < THREAD_TABLE_SZ; i++) { for (p = GC_threads[i]; p != 0; p = p -> next) { - if (!THREAD_EQUAL(p -> id, my_thread)) { + if (!THREAD_EQUAL(p -> id, self)) { if (p -> flags & FINISHED) continue; if (p -> thread_blocked) /* Will wait */ continue; # ifndef GC_OPENBSD_THREADS @@ -716,7 +716,7 @@ GC_INNER void GC_stop_world(void) GC_INNER void GC_start_world(void) { # ifndef NACL - pthread_t my_thread = pthread_self(); + pthread_t self = pthread_self(); register int i; register GC_thread p; # ifndef GC_OPENBSD_THREADS @@ -736,7 +736,7 @@ GC_INNER void GC_start_world(void) # endif for (i = 0; i < THREAD_TABLE_SZ; i++) { for (p = GC_threads[i]; p != 0; p = p -> next) { - if (!THREAD_EQUAL(p -> id, my_thread)) { + if (!THREAD_EQUAL(p -> id, self)) { if (p -> flags & FINISHED) continue; if (p -> thread_blocked) continue; # ifndef GC_OPENBSD_THREADS diff --git a/pthread_support.c b/pthread_support.c index 34793248..a6a5a5a3 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -1162,22 +1162,11 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn, return client_data; /* result */ } -GC_API int GC_CALL GC_unregister_my_thread(void) +STATIC void GC_unregister_my_thread_inner(GC_thread me) { - pthread_t self = pthread_self(); - GC_thread me; - IF_CANCEL(int cancel_state;) - DCL_LOCK_STATE; - # ifdef DEBUG_THREADS - GC_log_printf("Unregistering thread 0x%x\n", (unsigned)self); + GC_log_printf("Unregistering thread 0x%x\n", (unsigned)pthread_self()); # endif - LOCK(); - DISABLE_CANCEL(cancel_state); - /* Wait for any GC that may be marking from our stack to */ - /* complete before we remove this thread. */ - GC_wait_for_gc_completion(FALSE); - me = GC_lookup_thread(self); GC_ASSERT(!(me -> flags & FINISHED)); # if defined(THREAD_LOCAL_ALLOC) GC_destroy_thread_local(&(me->tlfs)); @@ -1190,13 +1179,27 @@ GC_API int GC_CALL GC_unregister_my_thread(void) } # endif if (me -> flags & DETACHED) { - GC_delete_thread(self); + GC_delete_thread(pthread_self()); } else { me -> flags |= FINISHED; } # if defined(THREAD_LOCAL_ALLOC) GC_remove_specific(GC_thread_key); # endif +} + +GC_API int GC_CALL GC_unregister_my_thread(void) +{ + pthread_t self = pthread_self(); + IF_CANCEL(int cancel_state;) + DCL_LOCK_STATE; + + LOCK(); + DISABLE_CANCEL(cancel_state); + /* Wait for any GC that may be marking from our stack to */ + /* complete before we remove this thread. */ + GC_wait_for_gc_completion(FALSE); + GC_unregister_my_thread_inner(GC_lookup_thread(self)); RESTORE_CANCEL(cancel_state); UNLOCK(); return GC_SUCCESS; @@ -1209,7 +1212,15 @@ GC_API int GC_CALL GC_unregister_my_thread(void) /* resources or id anyway. */ GC_INNER void GC_thread_exit_proc(void *arg) { - GC_unregister_my_thread(); + IF_CANCEL(int cancel_state;) + DCL_LOCK_STATE; + + LOCK(); + DISABLE_CANCEL(cancel_state); + GC_wait_for_gc_completion(FALSE); + GC_unregister_my_thread_inner((GC_thread)arg); + RESTORE_CANCEL(cancel_state); + UNLOCK(); } GC_API int WRAP_FUNC(pthread_join)(pthread_t thread, void **retval) @@ -1403,7 +1414,7 @@ struct start_info { /* Called from GC_inner_start_routine(). Defined in this file to */ /* minimize the number of include files in pthread_start.c (because */ /* sem_t and sem_post() are not used that file directly). */ -GC_INNER void * GC_start_rtn_prepare_thread(void *(**pstart)(void *), +GC_INNER GC_thread GC_start_rtn_prepare_thread(void *(**pstart)(void *), void **pstart_arg, struct GC_stack_base *sb, void *arg) { diff --git a/win32_threads.c b/win32_threads.c index 33227cae..a9b406ab 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -707,7 +707,7 @@ GC_API void GC_CALL GC_allow_register_threads(void) GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb) { - DWORD t = GetCurrentThreadId(); + DWORD thread_id = GetCurrentThreadId(); DCL_LOCK_STATE; if (GC_need_to_lock == FALSE) @@ -715,8 +715,8 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb) /* We lock here, since we want to wait for an ongoing GC. */ LOCK(); - if (0 == GC_lookup_thread_inner(t)) { - GC_register_my_thread_inner(sb, t); + if (0 == GC_lookup_thread_inner(thread_id)) { + GC_register_my_thread_inner(sb, thread_id); UNLOCK(); return GC_SUCCESS; } else { @@ -743,15 +743,15 @@ GC_API int GC_CALL GC_unregister_my_thread(void) GC_delete_thread(GetCurrentThreadId()); # endif } else { - DWORD t = GetCurrentThreadId(); + DWORD thread_id = GetCurrentThreadId(); LOCK(); # if defined(THREAD_LOCAL_ALLOC) { - GC_thread me = GC_lookup_thread_inner(t); + GC_thread me = GC_lookup_thread_inner(thread_id); GC_destroy_thread_local(&(me->tlfs)); } # endif - GC_delete_thread(t); + GC_delete_thread(thread_id); UNLOCK(); } return GC_SUCCESS; @@ -765,7 +765,7 @@ GC_API int GC_CALL GC_unregister_my_thread(void) GC_INNER void GC_do_blocking_inner(ptr_t data, void * context) { struct blocking_data * d = (struct blocking_data *) data; - DWORD t = GetCurrentThreadId(); + DWORD thread_id = GetCurrentThreadId(); GC_thread me; # ifdef IA64 ptr_t stack_ptr = GC_save_regs_in_stack(); @@ -773,7 +773,7 @@ GC_INNER void GC_do_blocking_inner(ptr_t data, void * context) DCL_LOCK_STATE; LOCK(); - me = GC_lookup_thread_inner(t); + me = GC_lookup_thread_inner(thread_id); GC_ASSERT(me -> thread_blocked_sp == NULL); # ifdef IA64 me -> backing_store_ptr = stack_ptr; @@ -1300,7 +1300,7 @@ STATIC word GC_push_stack_for(GC_thread thread, DWORD me) GC_INNER void GC_push_all_stacks(void) { - DWORD me = GetCurrentThreadId(); + DWORD thread_id = GetCurrentThreadId(); GC_bool found_me = FALSE; # ifndef SMALL_CONFIG unsigned nthreads = 0; @@ -1317,8 +1317,8 @@ GC_INNER void GC_push_all_stacks(void) # ifndef SMALL_CONFIG ++nthreads; # endif - total_size += GC_push_stack_for(t, me); - if (t -> id == me) found_me = TRUE; + total_size += GC_push_stack_for(t, thread_id); + if (t -> id == thread_id) found_me = TRUE; } } } else @@ -1332,8 +1332,8 @@ GC_INNER void GC_push_all_stacks(void) # ifndef SMALL_CONFIG ++nthreads; # endif - total_size += GC_push_stack_for(t, me); - if (t -> id == me) found_me = TRUE; + total_size += GC_push_stack_for(t, thread_id); + if (t -> id == thread_id) found_me = TRUE; } } } @@ -1854,10 +1854,10 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, GC_INNER void GC_wait_marker(void) { HANDLE event = mark_cv; - DWORD id = GetCurrentThreadId(); + DWORD thread_id = GetCurrentThreadId(); int i = (int)GC_markers - 1; while (i-- > 0) { - if (GC_marker_Id[i] == id) { + if (GC_marker_Id[i] == thread_id) { event = GC_marker_cv[i]; break; } @@ -1873,11 +1873,11 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, GC_INNER void GC_notify_all_marker(void) { - DWORD id = GetCurrentThreadId(); + DWORD thread_id = GetCurrentThreadId(); int i = (int)GC_markers - 1; while (i-- > 0) { /* Notify every marker ignoring self (for efficiency). */ - if (SetEvent(GC_marker_Id[i] != id ? GC_marker_cv[i] : + if (SetEvent(GC_marker_Id[i] != thread_id ? GC_marker_cv[i] : mark_cv) == FALSE) ABORT("SetEvent() failed"); } @@ -1985,8 +1985,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, GC_register_my_thread(sb); /* This waits for an in-progress GC. */ # ifdef DEBUG_THREADS - GC_log_printf("thread 0x%lx starting...\n", - (long)GetCurrentThreadId()); + GC_log_printf("thread 0x%lx starting...\n", (long)GetCurrentThreadId()); # endif GC_free(arg); |