diff options
| author | Russ Cox <rsc@golang.org> | 2009-01-27 14:01:20 -0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2009-01-27 14:01:20 -0800 |
| commit | 53e69e1db5d5960b33c93e05236afaca7f110b2b (patch) | |
| tree | eed590ded955f1f25cb25203b5ca94ece0716b75 /src/runtime/rt1_amd64_linux.c | |
| parent | 47ab1c1e994847279b875da6255b773e2aefc7b5 (diff) | |
| download | go-53e69e1db5d5960b33c93e05236afaca7f110b2b.tar.xz | |
various race conditions.
R=r
DELTA=43 (29 added, 5 deleted, 9 changed)
OCL=23608
CL=23611
Diffstat (limited to 'src/runtime/rt1_amd64_linux.c')
| -rw-r--r-- | src/runtime/rt1_amd64_linux.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/src/runtime/rt1_amd64_linux.c b/src/runtime/rt1_amd64_linux.c index c0c2038053..5b3e458094 100644 --- a/src/runtime/rt1_amd64_linux.c +++ b/src/runtime/rt1_amd64_linux.c @@ -301,13 +301,11 @@ futexwakeup(uint32 *addr) // else return 0; // but atomically. -void -lock(Lock *l) +static void +futexlock(Lock *l) { uint32 v; - m->locks++; - again: v = l->key; if((v&1) == 0){ @@ -346,13 +344,11 @@ again: goto again; } -void -unlock(Lock *l) +static void +futexunlock(Lock *l) { uint32 v; - m->locks--; - // Atomically get value and clear lock bit. again: v = l->key; @@ -366,6 +362,24 @@ again: futexwakeup(&l->key); } +void +lock(Lock *l) +{ + if(m->locks < 0) + throw("lock count"); + m->locks++; + futexlock(l); +} + +void +unlock(Lock *l) +{ + m->locks--; + if(m->locks < 0) + throw("lock count"); + futexunlock(l); +} + // One-time notifications. // @@ -383,20 +397,20 @@ void noteclear(Note *n) { n->lock.key = 0; // memset(n, 0, sizeof *n) - lock(&n->lock); + futexlock(&n->lock); } void notewakeup(Note *n) { - unlock(&n->lock); + futexunlock(&n->lock); } void notesleep(Note *n) { - lock(&n->lock); - unlock(&n->lock); // Let other sleepers find out too. + futexlock(&n->lock); + futexunlock(&n->lock); // Let other sleepers find out too. } |
