diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-12-31 18:50:45 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-12-31 18:50:45 +0300 |
commit | 2cd04cd95cef35180a021e83f7fb9ac268e6ab3b (patch) | |
tree | ea7fcf9f4f3635bf412c448aaac49800b75d65a3 /win32_threads.c | |
parent | 40b23a42c73ed11d384a5ed81e8f5eb126edb434 (diff) | |
download | bdwgc-2cd04cd95cef35180a021e83f7fb9ac268e6ab3b.tar.gz |
Uniform use of GC_lookup_by_pthread in GC_pthread_join/detach
(refactoring)
* include/private/pthread_support.h [GC_WIN32_THREADS && GC_PTHREADS]
(GC_lookup_by_pthread): Move declaration down.
* include/private/pthread_support.h [GC_PTHREADS && !GC_WIN32_THREADS]
(GC_lookup_by_pthread): Define as macro (to GC_lookup_thread).
* pthread_stop_world.c [!NACL && GC_ENABLE_SUSPEND_THREAD]
(GC_suspend_thread, GC_resume_thread, GC_is_thread_suspended): Use
GC_lookup_by_pthread() instead of GC_lookup_thread().
* pthread_support.c [!GC_NO_PTHREAD_CANCEL && GC_PTHREADS
&& CANCEL_SAFE] (GC_pthread_cancel): Likewise.
* pthread_support.c [GC_PTHREADS && !SN_TARGET_ORBIS
&& !SN_TARGET_PSP2] (GC_pthread_join, GC_pthread_detach): Likewise.
* pthread_support.c [GC_PTHREADS && !SN_TARGET_ORBIS
&& !SN_TARGET_PSP2 && GC_WIN32_THREADS] (GC_pthread_join,
GC_pthread_detach): Wrap GC_lookup_by_pthread() call into LOCK/UNLOCK.
* win32_threads.c [GC_PTHREADS] (GC_lookup_by_pthread): Refine comment;
define id local variable; remove hv_guess local variable;
replace break with return p; remove LOCK() and UNLOCK(); add assertion
that the GC lock is held.
Diffstat (limited to 'win32_threads.c')
-rw-r--r-- | win32_threads.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/win32_threads.c b/win32_threads.c index 0d1ec5a6..ea22e888 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -346,31 +346,26 @@ GC_INLINE LONG GC_get_max_thread_index(void) /* thread registration is made compatible with pthreads (and */ /* turned on). */ - /* We first try the cache. If that fails, we use a very slow */ - /* approach. */ - int hv_guess = THREAD_TABLE_INDEX(GET_PTHREAD_MAP_CACHE(thread)); + thread_id_t id = GET_PTHREAD_MAP_CACHE(thread); GC_thread p; - DCL_LOCK_STATE; + int hv; - LOCK(); - for (p = GC_threads[hv_guess]; p != NULL; p = p -> tm.next) { + GC_ASSERT(I_HOLD_LOCK()); + /* We first try the cache. */ + for (p = GC_threads[THREAD_TABLE_INDEX(id)]; + p != NULL; p = p -> tm.next) { if (THREAD_EQUAL(p -> pthread_id, thread)) - break; + return p; } - if (EXPECT(NULL == p, FALSE)) { - int hv; - - for (hv = 0; hv < THREAD_TABLE_SZ; ++hv) { - for (p = GC_threads[hv]; p != NULL; p = p -> tm.next) { - if (THREAD_EQUAL(p -> pthread_id, thread)) - break; - } - if (p != NULL) break; + /* If that fails, we use a very slow approach. */ + for (hv = 0; hv < THREAD_TABLE_SZ; ++hv) { + for (p = GC_threads[hv]; p != NULL; p = p -> tm.next) { + if (THREAD_EQUAL(p -> pthread_id, thread)) + return p; } } - UNLOCK(); - return p; + return NULL; } #endif /* GC_PTHREADS */ |