]> granicus.if.org Git - gc/commitdiff
Add assertion to LOCK definition that lock is not already held
authorIvan Maidanski <ivmai@mail.ru>
Mon, 15 Jul 2013 11:08:45 +0000 (15:08 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 15 Jul 2013 11:08:45 +0000 (15:08 +0400)
* include/private/gc_locks.h (UNCOND_LOCK): Add assertion that
I_DONT_HOLD_LOCK (lock is not held precondition).

include/private/gc_locks.h

index fb8a4635ea7e04d216d4fc70399b52e36c18c576..6696651de4d814e61d66e5785e4713aee48b5633 100644 (file)
@@ -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(); \
         /* 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() \
                 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 */
 #      include <pthread.h>
        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); }