diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2012-01-12 07:25:56 +0400 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2012-01-12 11:26:42 +0400 |
commit | ebad007ca2ee03800ccad740512bcbeec07439c2 (patch) | |
tree | 748baf1c42c4d61cb2bc66d568978ba6127d6332 | |
parent | 83c1eecd037ff4d3e3d19615ced970f566f5cc72 (diff) | |
download | bdwgc-ebad007ca2ee03800ccad740512bcbeec07439c2.tar.gz |
Improve GC_thread_is_registered implementation and testing
* pthread_support.c (GC_thread_is_registered): Call pthread_self
outside LOCK; add DCL_LOCK_STATE declaration; replace "ptr" local
variable with "GC_thread me" (and remove cast).
* win32_threads.c (GC_thread_is_registered): Fix implementation by
calling GC_lookup_thread_inner (now works the same as in
pthread_support.c).
* tests/test.c (run_one_test): Test GC_thread_is_registered (only if
THREADS).
-rw-r--r-- | pthread_support.c | 9 | ||||
-rw-r--r-- | tests/test.c | 6 | ||||
-rw-r--r-- | win32_threads.c | 10 |
3 files changed, 19 insertions, 6 deletions
diff --git a/pthread_support.c b/pthread_support.c index 9fd3432c..6d5c314e 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -647,13 +647,14 @@ GC_INNER unsigned char *GC_check_finalizer_nested(void) GC_API int GC_CALL GC_thread_is_registered(void) { - void *ptr; + pthread_t self = pthread_self(); + GC_thread me; + DCL_LOCK_STATE; LOCK(); - ptr = (void *)GC_lookup_thread(pthread_self()); + me = GC_lookup_thread(self); UNLOCK(); - - return ptr ? 1 : 0; + return me != NULL; } #ifdef HANDLE_FORK diff --git a/tests/test.c b/tests/test.c index 9125e750..ca7c6d42 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1078,6 +1078,12 @@ void run_one_test(void) GC_printf("Expect lots of problems\n"); # endif GC_FREE(0); +# ifdef THREADS + if (!GC_thread_is_registered()) { + GC_printf("Current thread is not registered with GC\n"); + FAIL; + } +# endif # ifndef DBG_HDRS_ALL collectable_count += 3; if ((GC_size(GC_malloc(7)) != 8 && diff --git a/win32_threads.c b/win32_threads.c index 579d1504..4bc0cb4e 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -586,8 +586,14 @@ GC_INNER unsigned char *GC_check_finalizer_nested(void) GC_API int GC_CALL GC_thread_is_registered(void) { - /* FIXME: Works only if registered by DllMain */ - return 1; + DWORD thread_id = GetCurrentThreadId(); + GC_thread me; + DCL_LOCK_STATE; + + LOCK(); + me = GC_lookup_thread_inner(thread_id); + UNLOCK(); + return me != NULL; } /* Make sure thread descriptor t is not protected by the VDB */ |