summaryrefslogtreecommitdiff
path: root/pthread_support.c
diff options
context:
space:
mode:
authorivmai <ivmai>2011-05-10 16:15:57 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:58 +0200
commitff325b9a6bf206b951bc30beb12c96d8de2e6334 (patch)
tree684ed74831a0ec9cb1c26af284c4f3d28c7962f3 /pthread_support.c
parentec6effaa02f0fa4a35d6238bdb408226a3d4ab19 (diff)
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".
Diffstat (limited to 'pthread_support.c')
-rw-r--r--pthread_support.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/pthread_support.c b/pthread_support.c
index 3479324..a6a5a5a 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)
{