]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix writebarrier throw in lock_sema
authorRuss Cox <rsc@golang.org>
Tue, 17 Mar 2015 19:07:05 +0000 (15:07 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 17 Mar 2015 19:20:11 +0000 (19:20 +0000)
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>
src/runtime/lock_sema.go
src/runtime/runtime2.go

index 47cb88335b2ed2bb23b0f48dca0d7b42029becca..d9d91c915534f25f7ab0498a7b9d0da669404990 100644 (file)
@@ -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
index 27700b6217caaa364893d28642169016a51bdf3a..6604b9920c11a49333842fd9a1a6e62b81196d0e 100644 (file)
@@ -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