summaryrefslogtreecommitdiff
path: root/pthread_support.c
diff options
context:
space:
mode:
authorivmai <ivmai>2011-05-11 09:19:46 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:58 +0200
commit88a952ac5dd3c0582a82a1f2acfa277f5eaf4047 (patch)
tree44b09f360c494466a599812bd6a70091884763d5 /pthread_support.c
parentd604870504cc8dd8870e8c1a6e719f88eb6c5ba7 (diff)
2011-05-11 Ivan Maidanski <ivmai@mail.ru>
* pthread_support.c (GC_unregister_my_thread_inner): Don't call GC_remove_specific. * include/private/thread_local_alloc.h (GC_remove_specific): Remove (since it is empty for all targets). * pthread_support.c (GC_record_stack_base): New inline function. * win32_threads.c (GC_record_stack_base): Ditto. * pthread_support.c (GC_register_my_thread_inner): Invoke GC_record_stack_base. * win32_threads.c (GC_register_my_thread_inner): Ditto. * pthread_support.c (GC_register_my_thread): If thread is FINISHED then call GC_record_stack_base, clear FINISHED, initialize thread-local list and return success. * win32_threads.c (GC_register_my_thread): Ditto. * include/gc.h (GC_register_my_thread): Update documentation. * include/private/thread_local_alloc.h (GC_thread_key): Ditto.
Diffstat (limited to 'pthread_support.c')
-rw-r--r--pthread_support.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/pthread_support.c b/pthread_support.c
index a6a5a5a..af16a57 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -1183,9 +1183,6 @@ STATIC void GC_unregister_my_thread_inner(GC_thread me)
} 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)
@@ -1344,6 +1341,20 @@ GC_API int WRAP_FUNC(pthread_detach)(pthread_t thread)
GC_INNER GC_bool GC_in_thread_creation = FALSE;
/* Protected by allocation lock. */
+GC_INLINE void GC_record_stack_base(GC_thread me,
+ const struct GC_stack_base *sb)
+{
+# ifndef GC_DARWIN_THREADS
+ me -> stop_info.stack_ptr = sb -> mem_base;
+# endif
+ me -> stack_end = sb -> mem_base;
+ if (me -> stack_end == NULL)
+ ABORT("Bad stack base in GC_register_my_thread");
+# ifdef IA64
+ me -> backing_store_end = sb -> reg_base;
+# endif
+}
+
STATIC GC_thread GC_register_my_thread_inner(const struct GC_stack_base *sb,
pthread_t my_pthread)
{
@@ -1356,15 +1367,8 @@ STATIC GC_thread GC_register_my_thread_inner(const struct GC_stack_base *sb,
ABORT("Failed to allocate memory for thread registering");
# ifdef GC_DARWIN_THREADS
me -> stop_info.mach_thread = mach_thread_self();
-# else
- me -> stop_info.stack_ptr = sb -> mem_base;
# endif
- me -> stack_end = sb -> mem_base;
- if (me -> stack_end == NULL)
- ABORT("Bad stack base in GC_register_my_thread");
-# ifdef IA64
- me -> backing_store_end = sb -> reg_base;
-# endif /* IA64 */
+ GC_record_stack_base(me, sb);
return me;
}
@@ -1387,8 +1391,13 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
LOCK();
me = GC_lookup_thread(self);
- if (0 == me) {
- me = GC_register_my_thread_inner(sb, self);
+ if (0 == me || (me -> flags & FINISHED) != 0) {
+ if (me == 0) {
+ me = GC_register_my_thread_inner(sb, self);
+ } else {
+ GC_record_stack_base(me, sb);
+ me -> flags &= ~FINISHED;
+ }
me -> flags |= DETACHED;
/* Treat as detached, since we do not need to worry about */
/* pointer results. */