Commit 06afc8b1 authored by Austin Clements's avatar Austin Clements

runtime: simplify the control flow in sweepone

Ending a loop with a break is confusing. Rewrite the loop so the
default behavior is to loop and then do the "post-loop" work outside
of the loop.

Change-Id: Ie49b4132541dfb5124c31a8163f2c883aa4abc75
Reviewed-on: https://go-review.googlesource.com/138155
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRick Hudson <rlh@golang.org>
parent a6df1cec
...@@ -88,10 +88,11 @@ func sweepone() uintptr { ...@@ -88,10 +88,11 @@ func sweepone() uintptr {
} }
atomic.Xadd(&mheap_.sweepers, +1) atomic.Xadd(&mheap_.sweepers, +1)
npages := ^uintptr(0) // Find a span to sweep.
var s *mspan
sg := mheap_.sweepgen sg := mheap_.sweepgen
for { for {
s := mheap_.sweepSpans[1-sg/2%2].pop() s = mheap_.sweepSpans[1-sg/2%2].pop()
if s == nil { if s == nil {
atomic.Store(&mheap_.sweepdone, 1) atomic.Store(&mheap_.sweepdone, 1)
break break
...@@ -106,9 +107,14 @@ func sweepone() uintptr { ...@@ -106,9 +107,14 @@ func sweepone() uintptr {
} }
continue continue
} }
if s.sweepgen != sg-2 || !atomic.Cas(&s.sweepgen, sg-2, sg-1) { if s.sweepgen == sg-2 && atomic.Cas(&s.sweepgen, sg-2, sg-1) {
continue break
} }
}
// Sweep the span we found.
npages := ^uintptr(0)
if s != nil {
npages = s.npages npages = s.npages
if !s.sweep(false) { if !s.sweep(false) {
// Span is still in-use, so this returned no // Span is still in-use, so this returned no
...@@ -116,7 +122,6 @@ func sweepone() uintptr { ...@@ -116,7 +122,6 @@ func sweepone() uintptr {
// move to the swept in-use list. // move to the swept in-use list.
npages = 0 npages = 0
} }
break
} }
// Decrement the number of active sweepers and if this is the // Decrement the number of active sweepers and if this is the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment