From 65351f94a50ed60bdb59cf12e02c87d21eeb03dd Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Wed, 1 Feb 2006 14:26:05 +0000 Subject: [PATCH] 2006-02-01 Zoltan Varga * pthread_support.c (GC_thread_deregister_foreign): New public API function to deregister a foreign thread from the GC. (GC_destroy_thread_local): Clean up the TLS key too. svn path=/trunk/mono/; revision=56387 --- ChangeLog | 5 +++++ include/private/pthread_support.h | 2 +- pthread_support.c | 23 ++++++++++++++++++++--- solaris_threads.c | 4 ++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index ddc4befc..8c47519f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ +2006-02-01 Zoltan Varga + * pthread_support.c (GC_thread_deregister_foreign): New public API + function to deregister a foreign thread from the GC. + (GC_destroy_thread_local): Clean up the TLS key too. + Tue Jan 24 12:34:06 CET 2006 Paolo Molaro * *: update from upstream changes. diff --git a/include/private/pthread_support.h b/include/private/pthread_support.h index c2c48c22..b4a762b5 100644 --- a/include/private/pthread_support.h +++ b/include/private/pthread_support.h @@ -92,7 +92,7 @@ extern GC_bool GC_thr_initialized; GC_thread GC_lookup_thread(pthread_t id); -void GC_thread_deregister_foreign (void *data); +void GC_thread_deregister_foreign (void); void GC_stop_init(); diff --git a/pthread_support.c b/pthread_support.c index ac8df854..5a7b3769 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -223,7 +223,8 @@ static ptr_t size_zero_object = (ptr_t)(&size_zero_object); void GC_delete_thread(pthread_t id); -void GC_thread_deregister_foreign (void *data) +/* Called by pthreads when the TLS entry is destroyed */ +static void GC_thread_deregister_foreign_internal (void *data) { GC_thread me = (GC_thread)data; /* GC_fprintf1( "\n\n\n\n --- Deregister %x ---\n\n\n\n\n", me->flags ); */ @@ -243,7 +244,7 @@ void GC_init_thread_local(GC_thread p) int i; if (!keys_initialized) { - if (0 != GC_key_create(&GC_thread_key, GC_thread_deregister_foreign)) { + if (0 != GC_key_create(&GC_thread_key, GC_thread_deregister_foreign_internal)) { ABORT("Failed to create key for local allocator"); } keys_initialized = TRUE; @@ -283,6 +284,7 @@ void GC_destroy_thread_local(GC_thread p) # ifdef GC_GCJ_SUPPORT return_freelists(p -> gcj_freelists, GC_gcjobjfreelist); # endif + GC_setspecific(GC_thread_key, NULL); } extern GC_PTR GC_generic_malloc_many(); @@ -630,7 +632,7 @@ void GC_delete_thread(pthread_t id) int hv = ((word)id) % THREAD_TABLE_SZ; register GC_thread p = GC_threads[hv]; register GC_thread prev = 0; - + while (!pthread_equal(p -> id, id)) { prev = p; p = p -> next; @@ -1260,6 +1262,21 @@ int GC_thread_register_foreign (void *base_addr) return me != NULL; } +void GC_thread_deregister_foreign (void) +{ + GC_thread me; + + LOCK (); + me = GC_lookup_thread (pthread_self ()); + if (me->flags & FOREIGN_THREAD) { + GC_delete_thread (me->id); +#if defined(THREAD_LOCAL_ALLOC) && !defined(DBG_HDRS_ALL) + GC_destroy_thread_local (me); +#endif + } + UNLOCK (); +} + void * GC_start_routine(void * arg) { int dummy; diff --git a/solaris_threads.c b/solaris_threads.c index 5c49c120..a2f0a5d2 100644 --- a/solaris_threads.c +++ b/solaris_threads.c @@ -641,6 +641,10 @@ int GC_thread_register_foreign (void *base_addr) return 0; } +void GC_thread_deregister_foreign (void) +{ +} + /* Solaris 2/Intel uses an initial stack size limit slightly bigger than the SPARC default of 8 MB. Account for this to warn only if the user has raised the limit beyond the default. -- 2.40.0