]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: unset m->locks after actual lock unlock
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 15 May 2013 12:48:41 +0000 (16:48 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Wed, 15 May 2013 12:48:41 +0000 (16:48 +0400)
This is needed for preemptive scheduler,
it will preempt only when m->locks==0,
and we do not want to be preempted while
we have not completely unlocked the lock.

R=golang-dev, khr, iant
CC=golang-dev
https://golang.org/cl/9196047

src/pkg/runtime/lock_futex.c
src/pkg/runtime/lock_sema.c

index 3c2ef4ede079a05d805bbbf75942a1daaa179ded..d20b63c329b3bafb3e3737837fb288069e191530 100644 (file)
@@ -91,14 +91,14 @@ runtime·unlock(Lock *l)
 {
        uint32 v;
 
-       if(--m->locks < 0)
-               runtime·throw("runtime·unlock: lock count");
-
        v = runtime·xchg((uint32*)&l->key, MUTEX_UNLOCKED);
        if(v == MUTEX_UNLOCKED)
                runtime·throw("unlock of unlocked lock");
        if(v == MUTEX_SLEEPING)
                runtime·futexwakeup((uint32*)&l->key, 1);
+
+       if(--m->locks < 0)
+               runtime·throw("runtime·unlock: lock count");
 }
 
 // One-time notifications.
index ec4b15a98a1c7aca7bda3e656a2a977f25f223f5..80674e8a5e3d0011cf188f605eafb492dc9a31d7 100644 (file)
@@ -93,9 +93,6 @@ runtime·unlock(Lock *l)
        uintptr v;
        M *mp;
 
-       if(--m->locks < 0)
-               runtime·throw("runtime·unlock: lock count");
-
        for(;;) {
                v = (uintptr)runtime·atomicloadp((void**)&l->key);
                if(v == LOCKED) {
@@ -112,6 +109,9 @@ runtime·unlock(Lock *l)
                        }
                }
        }
+
+       if(--m->locks < 0)
+               runtime·throw("runtime·unlock: lock count");
 }
 
 // One-time notifications.