diff options
| author | Russ Cox <rsc@golang.org> | 2015-03-17 15:07:05 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-03-17 19:20:11 +0000 |
| commit | 87ec06f96165fcbacf06904cc70a5f19c2a6c00a (patch) | |
| tree | 8e093a1f9a92a8e38584678d1a53a71293103d23 /src | |
| parent | 41dbcc19ef09a15f464eb3931c60b04e33cf72bb (diff) | |
| download | go-87ec06f96165fcbacf06904cc70a5f19c2a6c00a.tar.xz | |
runtime: fix writebarrier throw in lock_sema
The value in question is really a bit pattern
(a pointer with extra bits thrown in),
so treat it as a uintptr instead, avoiding the
generation of a write barrier when there
might not be a p.
Also add the obligatory //go:nowritebarrier.
Change-Id: I4ea097945dd7093a140f4740bcadca3ce7191971
Reviewed-on: https://go-review.googlesource.com/7667
Reviewed-by: Rick Hudson <rlh@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/runtime/lock_sema.go | 6 | ||||
| -rw-r--r-- | src/runtime/runtime2.go | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/runtime/lock_sema.go b/src/runtime/lock_sema.go index 47cb88335b..d9d91c9155 100644 --- a/src/runtime/lock_sema.go +++ b/src/runtime/lock_sema.go @@ -72,7 +72,7 @@ Loop: // for this lock, chained through m->nextwaitm. // Queue this M. for { - gp.m.nextwaitm = (*m)((unsafe.Pointer)(v &^ locked)) + gp.m.nextwaitm = v &^ locked if casuintptr(&l.key, v, uintptr(unsafe.Pointer(gp.m))|locked) { break } @@ -90,6 +90,8 @@ Loop: } } +//go:nowritebarrier +// We might not be holding a p in this code. func unlock(l *mutex) { gp := getg() var mp *m @@ -103,7 +105,7 @@ func unlock(l *mutex) { // Other M's are waiting for the lock. // Dequeue an M. mp = (*m)((unsafe.Pointer)(v &^ locked)) - if casuintptr(&l.key, v, uintptr(unsafe.Pointer(mp.nextwaitm))) { + if casuintptr(&l.key, v, mp.nextwaitm) { // Dequeued an M. Wake it. semawakeup(mp) break diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 27700b6217..6604b9920c 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -301,7 +301,7 @@ type m struct { freghi [16]uint32 // d[i] msb and f[i+16] fflag uint32 // floating point compare flags locked uint32 // tracking for lockosthread - nextwaitm *m // next m waiting for lock + nextwaitm uintptr // next m waiting for lock waitsema uintptr // semaphore for parking on locks waitsemacount uint32 waitsemalock uint32 |
