From: Zoltan Varga Date: Thu, 3 Mar 2005 21:09:34 +0000 (+0000) Subject: Add GC_thread_is_registered API function X-Git-Tag: gc7_3alpha2~229 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83c1eecd037ff4d3e3d19615ced970f566f5cc72;p=gc Add GC_thread_is_registered API function (Apply commit 9b40e5d from 'mono_libgc' branch) * include/gc.h (GC_thread_is_registered): Declare new API function (only if GC_THREADS). * pthread_support.c (GC_thread_is_registered): New API function implementation. * win32_threads.c (GC_thread_is_registered): Likewise. --- diff --git a/include/gc.h b/include/gc.h index 54a9facc..27033dce 100644 --- a/include/gc.h +++ b/include/gc.h @@ -1122,6 +1122,10 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func /* fn */, /* A manually registered thread requires manual unregistering. */ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *); + /* Return TRUE if and only if the calling thread is registered with */ + /* the garbage collector. */ + GC_API int GC_CALL GC_thread_is_registered(void); + /* Unregister the current thread. Only an explicitly registered */ /* thread (i.e. for which GC_register_my_thread() returns GC_SUCCESS) */ /* is allowed (and required) to call this function. (As a special */ diff --git a/pthread_support.c b/pthread_support.c index 44118186..9fd3432c 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -645,6 +645,17 @@ GC_INNER unsigned char *GC_check_finalizer_nested(void) } #endif /* GC_ASSERTIONS && THREAD_LOCAL_ALLOC */ +GC_API int GC_CALL GC_thread_is_registered(void) +{ + void *ptr; + + LOCK(); + ptr = (void *)GC_lookup_thread(pthread_self()); + UNLOCK(); + + return ptr ? 1 : 0; +} + #ifdef HANDLE_FORK /* Remove all entries from the GC_threads table, except the */ /* one for the current thread. We need to do this in the child */ diff --git a/win32_threads.c b/win32_threads.c index a7952199..579d1504 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -584,6 +584,12 @@ GC_INNER unsigned char *GC_check_finalizer_nested(void) } #endif /* GC_ASSERTIONS && THREAD_LOCAL_ALLOC */ +GC_API int GC_CALL GC_thread_is_registered(void) +{ + /* FIXME: Works only if registered by DllMain */ + return 1; +} + /* Make sure thread descriptor t is not protected by the VDB */ /* implementation. */ /* Used to prevent write faults when the world is (partially) stopped, */