From 991f1a8a5ced31df77ea81a1f53116a8b5f34eea Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 15 Jul 2013 16:02:36 +0400 Subject: [PATCH] Add double-lock assertion to GC_acquire_mark_lock * pthread_support.c (GC_acquire_mark_lock): Add assertion that GC_mark_lock_holder is not set to the current thread on the function entry (i.e., assertion against double lock). * win32_threads.c (GC_acquire_mark_lock): Likewise. --- pthread_support.c | 1 + win32_threads.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/pthread_support.c b/pthread_support.c index 975c0816..334be501 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -1963,6 +1963,7 @@ static pthread_cond_t builder_cv = PTHREAD_COND_INITIALIZER; GC_INNER void GC_acquire_mark_lock(void) { + GC_ASSERT(GC_mark_lock_holder != NUMERIC_THREAD_ID(pthread_self())); GC_generic_lock(&mark_mutex); # ifdef GC_ASSERTIONS GC_mark_lock_holder = NUMERIC_THREAD_ID(pthread_self()); diff --git a/win32_threads.c b/win32_threads.c index 32e42ce3..2462c2a3 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -1786,6 +1786,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, GC_INNER void GC_acquire_mark_lock(void) { + GC_ASSERT(GC_mark_lock_holder != NUMERIC_THREAD_ID(pthread_self())); if (pthread_mutex_lock(&mark_mutex) != 0) { ABORT("pthread_mutex_lock failed"); } @@ -1971,6 +1972,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, GC_INNER void GC_acquire_mark_lock(void) { + GC_ASSERT(GC_mark_lock_holder != (unsigned long)GetCurrentThreadId()); # ifdef DONT_USE_SIGNALANDWAIT if (InterlockedExchange(&GC_mark_mutex_state, 1 /* locked */) != 0) # else -- 2.40.0