]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert netpollWaiters to internal atomic type
authorAndy Pan <panjf2000@gmail.com>
Wed, 24 Aug 2022 18:26:08 +0000 (02:26 +0800)
committerMichael Pratt <mpratt@google.com>
Thu, 25 Aug 2022 21:52:20 +0000 (21:52 +0000)
Updates #53821

Change-Id: I8776382b3eb0b7752cfc0d9287b707039d3f05c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/425358
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: hopehook <hopehook@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/netpoll.go
src/runtime/netpoll_stub.go
src/runtime/proc.go

index 8bcdce549b37dfe137e17ade008709791579e66f..5ac1f37048c080908deb2bc1a83134ce4ecd5035 100644 (file)
@@ -181,7 +181,7 @@ var (
        netpollInited   atomic.Uint32
 
        pollcache      pollCache
-       netpollWaiters uint32
+       netpollWaiters atomic.Uint32
 )
 
 //go:linkname poll_runtime_pollServerInit internal/poll.runtime_pollServerInit
@@ -483,13 +483,13 @@ func netpollblockcommit(gp *g, gpp unsafe.Pointer) bool {
                // Bump the count of goroutines waiting for the poller.
                // The scheduler uses this to decide whether to block
                // waiting for the poller if there is nothing else to do.
-               atomic.Xadd(&netpollWaiters, 1)
+               netpollWaiters.Add(1)
        }
        return r
 }
 
 func netpollgoready(gp *g, traceskip int) {
-       atomic.Xadd(&netpollWaiters, -1)
+       netpollWaiters.Add(-1)
        goready(gp, traceskip+1)
 }
 
index 5860e1db03e5f05252c404e9ff8e8b1c6caae372..14cf0c327fd7588122cb2153476cdd6e8e94abcf 100644 (file)
@@ -9,7 +9,7 @@ package runtime
 import "runtime/internal/atomic"
 
 var netpollInited atomic.Uint32
-var netpollWaiters uint32
+var netpollWaiters atomic.Uint32
 
 var netpollStubLock mutex
 var netpollNote note
index d572fa2215e9fd68d78939bde42c60eb4e6e52f0..3038b9819d0391ec8c68cbc367ff781daac4a226 100644 (file)
@@ -2659,7 +2659,7 @@ top:
        // blocked thread (e.g. it has already returned from netpoll, but does
        // not set lastpoll yet), this thread will do blocking netpoll below
        // anyway.
-       if netpollinited() && atomic.Load(&netpollWaiters) > 0 && sched.lastpoll.Load() != 0 {
+       if netpollinited() && netpollWaiters.Load() > 0 && sched.lastpoll.Load() != 0 {
                if list := netpoll(0); !list.empty() { // non-blocking
                        gp := list.pop()
                        injectglist(&list)
@@ -2851,7 +2851,7 @@ top:
        }
 
        // Poll network until next timer.
-       if netpollinited() && (atomic.Load(&netpollWaiters) > 0 || pollUntil != 0) && sched.lastpoll.Swap(0) != 0 {
+       if netpollinited() && (netpollWaiters.Load() > 0 || pollUntil != 0) && sched.lastpoll.Swap(0) != 0 {
                sched.pollUntil.Store(pollUntil)
                if mp.p != 0 {
                        throw("findrunnable: netpoll with p")
@@ -2924,7 +2924,7 @@ func pollWork() bool {
        if !runqempty(p) {
                return true
        }
-       if netpollinited() && atomic.Load(&netpollWaiters) > 0 && sched.lastpoll.Load() != 0 {
+       if netpollinited() && netpollWaiters.Load() > 0 && sched.lastpoll.Load() != 0 {
                if list := netpoll(0); !list.empty() {
                        injectglist(&list)
                        return true