]> granicus.if.org Git - gc/commitdiff
Add GC_thread_is_registered API function
authorZoltan Varga <vargaz@gmail.com>
Thu, 3 Mar 2005 21:09:34 +0000 (21:09 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 12 Jan 2012 06:58:29 +0000 (10:58 +0400)
(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.

include/gc.h
pthread_support.c
win32_threads.c

index 54a9facc2ee30e03baa6dca5636a295dfa5d1daa..27033dce7266f976b5bbca6c1d1d2edeb2b8d769 100644 (file)
@@ -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    */
index 44118186408d88f3bbf2d94d44058b988231fb91..9fd3432ce52b7f98bf7e2cc4bb351c155df28267 100644 (file)
@@ -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 */
index a7952199ccefc0802e5786a7afd32b044e2382be..579d150415ddb53b66479b6407883237310441e3 100644 (file)
@@ -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,  */