From: Ivan Maidanski Date: Mon, 15 Jul 2013 11:08:45 +0000 (+0400) Subject: Add assertion to LOCK definition that lock is not already held X-Git-Tag: gc7_4_0~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89ff5faae1af92198706fa406b5780e6a10df0bf;p=gc Add assertion to LOCK definition that lock is not already held * include/private/gc_locks.h (UNCOND_LOCK): Add assertion that I_DONT_HOLD_LOCK (lock is not held precondition). --- diff --git a/include/private/gc_locks.h b/include/private/gc_locks.h index fb8a4635..6696651d 100644 --- a/include/private/gc_locks.h +++ b/include/private/gc_locks.h @@ -59,7 +59,8 @@ GC_EXTERN CRITICAL_SECTION GC_allocate_ml; # ifdef GC_ASSERTIONS # define UNCOND_LOCK() \ - { EnterCriticalSection(&GC_allocate_ml); \ + { GC_ASSERT(I_DONT_HOLD_LOCK()); \ + EnterCriticalSection(&GC_allocate_ml); \ SET_LOCK_HOLDER(); } # define UNCOND_UNLOCK() \ { GC_ASSERT(I_HOLD_LOCK()); UNSET_LOCK_HOLDER(); \ @@ -116,7 +117,8 @@ /* GC_call_with_alloc_lock. */ # ifdef GC_ASSERTIONS # define UNCOND_LOCK() \ - { if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \ + { GC_ASSERT(I_DONT_HOLD_LOCK()); \ + if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \ GC_lock(); \ SET_LOCK_HOLDER(); } # define UNCOND_UNLOCK() \ @@ -124,7 +126,8 @@ AO_CLEAR(&GC_allocate_lock); } # else # define UNCOND_LOCK() \ - { if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \ + { GC_ASSERT(I_DONT_HOLD_LOCK()); \ + if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \ GC_lock(); } # define UNCOND_UNLOCK() AO_CLEAR(&GC_allocate_lock) # endif /* !GC_ASSERTIONS */ @@ -137,7 +140,8 @@ # include GC_EXTERN pthread_mutex_t GC_allocate_ml; # ifdef GC_ASSERTIONS -# define UNCOND_LOCK() { GC_lock(); SET_LOCK_HOLDER(); } +# define UNCOND_LOCK() { GC_ASSERT(I_DONT_HOLD_LOCK()); \ + GC_lock(); SET_LOCK_HOLDER(); } # define UNCOND_UNLOCK() \ { GC_ASSERT(I_HOLD_LOCK()); UNSET_LOCK_HOLDER(); \ pthread_mutex_unlock(&GC_allocate_ml); }