aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/proc.go
diff options
context:
space:
mode:
authorAndy Pan <panjf2000@gmail.com>2021-05-06 09:04:03 +0800
committerAustin Clements <austin@google.com>2021-08-31 13:54:19 +0000
commit3920d6f2085559ae262d651b00bf8b29f953580a (patch)
tree423aa9be3d75bdd06a34ab19a916ad1ce52ed7ba /src/runtime/proc.go
parentf118d145a56be294e578fb20e0e2fdde2a92846d (diff)
downloadgo-3920d6f2085559ae262d651b00bf8b29f953580a.tar.gz
go-3920d6f2085559ae262d651b00bf8b29f953580a.zip
runtime: eliminate the redundant for loop in runqget()
Change-Id: If9b283bbef3ff12a64d34b07491aee3396852f05 Reviewed-on: https://go-review.googlesource.com/c/go/+/317509 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/proc.go')
-rw-r--r--src/runtime/proc.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 55023e3f9f..197441dfa7 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -5994,14 +5994,12 @@ func runqputbatch(pp *p, q *gQueue, qsize int) {
// Executed only by the owner P.
func runqget(_p_ *p) (gp *g, inheritTime bool) {
// If there's a runnext, it's the next G to run.
- for {
- next := _p_.runnext
- if next == 0 {
- break
- }
- if _p_.runnext.cas(next, 0) {
- return next.ptr(), true
- }
+ next := _p_.runnext
+ // If the runnext is non-0 and the CAS fails, it could only have been stolen by another P,
+ // because other Ps can race to set runnext to 0, but only the current P can set it to non-0.
+ // Hence, there's no need to retry this CAS if it falls.
+ if next != 0 && _p_.runnext.cas(next, 0) {
+ return next.ptr(), true
}
for {