aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mgcsweep.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2018-09-19 16:42:13 -0400
committerAustin Clements <austin@google.com>2018-09-27 18:04:50 +0000
commit06afc8b152bc01e1b4f5dce074bae531dd29a9b9 (patch)
treec727d1fe2254110506cb32bd16e5ea9b5c20526b /src/runtime/mgcsweep.go
parenta6df1cece7f6b62a1e1b09f9027692ac0d5411a1 (diff)
downloadgo-06afc8b152bc01e1b4f5dce074bae531dd29a9b9.tar.gz
go-06afc8b152bc01e1b4f5dce074bae531dd29a9b9.zip
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: Rick Hudson <rlh@golang.org>
Diffstat (limited to 'src/runtime/mgcsweep.go')
-rw-r--r--src/runtime/mgcsweep.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go
index ecfdee59f4..5cdede002a 100644
--- a/src/runtime/mgcsweep.go
+++ b/src/runtime/mgcsweep.go
@@ -88,10 +88,11 @@ func sweepone() uintptr {
}
atomic.Xadd(&mheap_.sweepers, +1)
- npages := ^uintptr(0)
+ // Find a span to sweep.
+ var s *mspan
sg := mheap_.sweepgen
for {
- s := mheap_.sweepSpans[1-sg/2%2].pop()
+ s = mheap_.sweepSpans[1-sg/2%2].pop()
if s == nil {
atomic.Store(&mheap_.sweepdone, 1)
break
@@ -106,9 +107,14 @@ func sweepone() uintptr {
}
continue
}
- if s.sweepgen != sg-2 || !atomic.Cas(&s.sweepgen, sg-2, sg-1) {
- continue
+ if s.sweepgen == sg-2 && atomic.Cas(&s.sweepgen, sg-2, sg-1) {
+ break
}
+ }
+
+ // Sweep the span we found.
+ npages := ^uintptr(0)
+ if s != nil {
npages = s.npages
if !s.sweep(false) {
// Span is still in-use, so this returned no
@@ -116,7 +122,6 @@ func sweepone() uintptr {
// move to the swept in-use list.
npages = 0
}
- break
}
// Decrement the number of active sweepers and if this is the