Bug 405025 ASSERT_VALID_LOCK failed r=gijs a=dsicore
authortimeless@mozdev.org
Tue, 26 Feb 2008 07:04:13 -0800
changeset 12257 4cfa3f1ffdbf3a170c4280f113a3fe63f7b5cfe2
parent 12256 c85cd6fba5dae6bfd69d9f62383c7093be2f9822
child 12258 3df1c9540d0e1e8d3f8a63ce20572968d99f1a14
push idunknown
push userunknown
push dateunknown
reviewersgijs, dsicore
bugs405025
milestone1.9b4pre
Bug 405025 ASSERT_VALID_LOCK failed r=gijs a=dsicore
js/jsd/jsd_lock.c
--- a/js/jsd/jsd_lock.c
+++ b/js/jsd/jsd_lock.c
@@ -98,17 +98,16 @@ JS_END_MACRO
 
 #ifdef DEBUG
 #define JSD_LOCK_SIG 0x10CC10CC
 void ASSERT_VALID_LOCK(JSDStaticLock* lock)
 {
     JS_ASSERT(lock);
     JS_ASSERT(lock->lock);
     JS_ASSERT(lock->count >= 0);
-    JS_ASSERT((! lock->count && ! lock->owner) || (lock->count && lock->owner));
     JS_ASSERT(lock->sig == (uint16) JSD_LOCK_SIG);
 }    
 #else
 #define ASSERT_VALID_LOCK(x) ((void)0)
 #endif
 
 void*
 jsd_CreateLock()
@@ -129,62 +128,65 @@ jsd_CreateLock()
 #endif
     return lock;
 }    
 
 void
 jsd_Lock(JSDStaticLock* lock)
 {
     void* me;
-
+    ASSERT_VALID_LOCK(lock);
     _CURRENT_THREAD(me);
 
-    ASSERT_VALID_LOCK(lock);
-
     if(lock->owner == me)
+    {
         lock->count++;
+        JS_ASSERT(lock->count > 1);
+    }
     else
     {
         PR_Lock(lock->lock);            /* this can block... */
         JS_ASSERT(lock->owner == 0);
+        JS_ASSERT(lock->count == 0);
         lock->count = 1;
         lock->owner = me;
     }
-    ASSERT_VALID_LOCK(lock);
 }    
 
 void
 jsd_Unlock(JSDStaticLock* lock)
 {
     void* me;
-
     ASSERT_VALID_LOCK(lock);
     _CURRENT_THREAD(me);
 
+    /* it's an error to unlock a lock you don't own */
+    JS_ASSERT(lock->owner == me);
     if(lock->owner != me)
     {
-        JS_ASSERT(0);   /* it's an error to unlock a lock you don't own */
         return;
     }
     if(--lock->count == 0)
     {
         lock->owner = NULL;
         PR_Unlock(lock->lock);
     }
-    ASSERT_VALID_LOCK(lock);
 }    
 
 #ifdef DEBUG
 JSBool
 jsd_IsLocked(JSDStaticLock* lock)
 {
     void* me;
     ASSERT_VALID_LOCK(lock);
     _CURRENT_THREAD(me);
-    return lock->owner == me ? JS_TRUE : JS_FALSE;
+    if (lock->owner != me)
+        return JS_FALSE;
+    JS_ASSERT(lock->count > 0);
+    return JS_TRUE;
 }    
 #endif /* DEBUG */
 
 void*
 jsd_CurrentThread()
 {
     void* me;
     _CURRENT_THREAD(me);