summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-10-16 00:11:37 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-10-17 12:43:33 +0300
commit70fa0739e2b0e7791063fc6743e9e5aa98d02dad (patch)
tree8cd5bdb2e0262f84a1d0af6538b1fd602907690d
parentf970259118e2d9316eff0f59692f5f61363cfe72 (diff)
downloadbdwgc-70fa0739e2b0e7791063fc6743e9e5aa98d02dad.tar.gz
Unify GC_[mark_]lock_holder variable definition
(refactoring) * include/private/gc_locks.h [GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS] (NO_THREAD): Define in a single place. * include/private/gc_locks.h [(GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS) && GC_ASSERTIONS] (UNSET_LOCK_HOLDER): Likewise. * include/private/gc_locks.h [(GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS) && GC_ASSERTIONS] (GC_lock_holder): Declare in a single place. * include/private/gc_locks.h [GC_WIN32_THREADS && !USE_PTHREAD_LOCKS] (NO_THREAD): Change DWORD to unsigned long. * include/private/gc_locks.h [GC_WIN32_THREADS && !USE_PTHREAD_LOCKS && GC_ASSERTIONS] (GC_lock_holder): Likewise. * win32_threads.c [!USE_PTHREAD_LOCKS && GC_ASSERTIONS] (GC_lock_holder): Likewise. * win32_threads.c [PARALLEL_MARK && !GC_PTHREADS_PARAMARK && GC_ASSERTIONS] (GC_mark_lock_holder): Likewise. * include/private/gc_locks.h [(GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS) && GC_ASSERTIONS] (SET_LOCK_HOLDER, UNSET_LOCK_HOLDER): Cast to void. * win32_threads.c [GC_ASSERTIONS] (GC_lock_holder): Define in a single place (in the file).
-rw-r--r--include/private/gc_locks.h25
-rw-r--r--win32_threads.c12
2 files changed, 19 insertions, 18 deletions
diff --git a/include/private/gc_locks.h b/include/private/gc_locks.h
index e96c940a..f6fc461f 100644
--- a/include/private/gc_locks.h
+++ b/include/private/gc_locks.h
@@ -63,20 +63,27 @@
# endif
# endif
+# if defined(GC_WIN32_THREADS) && !defined(USE_PTHREAD_LOCKS) \
+ || defined(GC_PTHREADS)
+# define NO_THREAD ((unsigned long)(-1L))
+ /* != NUMERIC_THREAD_ID(pthread_self()) for any thread */
+# ifdef GC_ASSERTIONS
+ GC_EXTERN unsigned long GC_lock_holder;
+# define UNSET_LOCK_HOLDER() (void)(GC_lock_holder = NO_THREAD)
+# endif
+# endif /* GC_WIN32_THREADS || GC_PTHREADS */
+
# if defined(GC_WIN32_THREADS) && !defined(USE_PTHREAD_LOCKS)
-# define NO_THREAD (DWORD)(-1)
GC_EXTERN CRITICAL_SECTION GC_allocate_ml;
# ifdef GC_ASSERTIONS
- GC_EXTERN DWORD GC_lock_holder;
-# define SET_LOCK_HOLDER() GC_lock_holder = GetCurrentThreadId()
-# define UNSET_LOCK_HOLDER() GC_lock_holder = NO_THREAD
+# define SET_LOCK_HOLDER() (void)(GC_lock_holder = GetCurrentThreadId())
# define I_HOLD_LOCK() (!GC_need_to_lock \
- || GC_lock_holder == GetCurrentThreadId())
+ || GC_lock_holder == GetCurrentThreadId())
# ifdef THREAD_SANITIZER
# define I_DONT_HOLD_LOCK() TRUE /* Conservatively say yes */
# else
# define I_DONT_HOLD_LOCK() (!GC_need_to_lock \
- || GC_lock_holder != GetCurrentThreadId())
+ || GC_lock_holder != GetCurrentThreadId())
# endif
# define UNCOND_LOCK() \
{ GC_ASSERT(I_DONT_HOLD_LOCK()); \
@@ -124,8 +131,6 @@
/* will result in poor performance (as NUMERIC_THREAD_ID is */
/* defined to just a constant) and weak assertion checking. */
# endif
-# define NO_THREAD ((unsigned long)(-1l))
- /* != NUMERIC_THREAD_ID(pthread_self()) for any thread */
# ifdef SN_TARGET_PSP2
EXTERN_C_END
@@ -198,10 +203,8 @@
# endif /* !GC_ASSERTIONS */
# endif /* USE_PTHREAD_LOCKS */
# ifdef GC_ASSERTIONS
- GC_EXTERN unsigned long GC_lock_holder;
# define SET_LOCK_HOLDER() \
- GC_lock_holder = NUMERIC_THREAD_ID(pthread_self())
-# define UNSET_LOCK_HOLDER() GC_lock_holder = NO_THREAD
+ (void)(GC_lock_holder = NUMERIC_THREAD_ID(pthread_self()))
# define I_HOLD_LOCK() \
(!GC_need_to_lock \
|| GC_lock_holder == NUMERIC_THREAD_ID(pthread_self()))
diff --git a/win32_threads.c b/win32_threads.c
index 5a9d018a..11c38d6b 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -23,15 +23,13 @@
/* Allocation lock declarations. */
#if !defined(USE_PTHREAD_LOCKS)
GC_INNER CRITICAL_SECTION GC_allocate_ml;
-# ifdef GC_ASSERTIONS
- GC_INNER DWORD GC_lock_holder = NO_THREAD;
- /* Thread id for current holder of allocation lock */
-# endif
#else
GC_INNER pthread_mutex_t GC_allocate_ml = PTHREAD_MUTEX_INITIALIZER;
-# ifdef GC_ASSERTIONS
+#endif
+
+#ifdef GC_ASSERTIONS
GC_INNER unsigned long GC_lock_holder = NO_THREAD;
-# endif
+ /* Thread id for current holder of allocation lock */
#endif
#undef CreateThread
@@ -2205,7 +2203,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
}
# ifdef GC_ASSERTIONS
- STATIC DWORD GC_mark_lock_holder = NO_THREAD;
+ STATIC unsigned long GC_mark_lock_holder = NO_THREAD;
# define SET_MARK_LOCK_HOLDER \
(void)(GC_mark_lock_holder = GetCurrentThreadId())
# define UNSET_MARK_LOCK_HOLDER \