]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert g.selectDone to atomic type
authorhopehook <hopehook.com@gmail.com>
Thu, 25 Aug 2022 01:42:30 +0000 (09:42 +0800)
committerMichael Knyszek <mknyszek@google.com>
Fri, 26 Aug 2022 15:36:36 +0000 (15:36 +0000)
On the write side, g.selectDone has been converted
from non-atomic to atomic access.

For #53821.

Change-Id: Iac46bc6acce7eed51dfd990285dd57f0d58b4ae2
Reviewed-on: https://go-review.googlesource.com/c/go/+/425414
Run-TryBot: hopehook <hopehook@qq.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/runtime/chan.go
src/runtime/runtime2.go
src/runtime/select.go

index 853a300ab52bf352f37c3bf91e09852ee2f108d7..a9ef0781cef9a040192efeff867df70b29b27e8d 100644 (file)
@@ -791,7 +791,7 @@ func (q *waitq) dequeue() *sudog {
                // We use a flag in the G struct to tell us when someone
                // else has won the race to signal this goroutine but the goroutine
                // hasn't removed itself from the queue yet.
-               if sgp.isSelect && !atomic.Cas(&sgp.g.selectDone, 0, 1) {
+               if sgp.isSelect && !sgp.g.selectDone.CompareAndSwap(0, 1) {
                        continue
                }
 
index 2d6602071bec38e95781dfcf5176dd4a7b817445..19ccfcea0eed549b057e356a41e7bde0340ad348 100644 (file)
@@ -487,7 +487,7 @@ type g struct {
        cgoCtxt        []uintptr      // cgo traceback context
        labels         unsafe.Pointer // profiler labels
        timer          *timer         // cached timer for time.Sleep
-       selectDone     uint32         // are we participating in a select and did someone win the race?
+       selectDone     atomic.Uint32  // are we participating in a select and did someone win the race?
 
        // goroutineProfiled indicates the status of this goroutine's stack for the
        // current in-progress goroutine profile
index 2dd6333fa7ab86ccbbacd7a4c1593db3c4c9c960..1072465365e11cdb9a9a768ae9c1b788f4eb828b 100644 (file)
@@ -329,7 +329,7 @@ func selectgo(cas0 *scase, order0 *uint16, pc0 *uintptr, nsends, nrecvs int, blo
 
        sellock(scases, lockorder)
 
-       gp.selectDone = 0
+       gp.selectDone.Store(0)
        sg = (*sudog)(gp.param)
        gp.param = nil