]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/runtime/mcentral.go
runtime: refactor runtime->tracer API to appear more like a lock
[gostls13.git] / src / runtime / mcentral.go
index b1dcbd7e7ddc7006c2d08413d82e08d66485a163..e190b56c86b3ef4c0de2569056e94a1c0dc896b6 100644 (file)
@@ -84,8 +84,10 @@ func (c *mcentral) cacheSpan() *mspan {
        deductSweepCredit(spanBytes, 0)
 
        traceDone := false
-       if traceEnabled() {
-               traceGCSweepStart()
+       trace := traceAcquire()
+       if trace.ok() {
+               trace.GCSweepStart()
+               traceRelease(trace)
        }
 
        // If we sweep spanBudget spans without finding any free
@@ -157,9 +159,11 @@ func (c *mcentral) cacheSpan() *mspan {
                }
                sweep.active.end(sl)
        }
-       if traceEnabled() {
-               traceGCSweepDone()
+       trace = traceAcquire()
+       if trace.ok() {
+               trace.GCSweepDone()
                traceDone = true
+               traceRelease(trace)
        }
 
        // We failed to get a span from the mcentral so get one from mheap.
@@ -170,8 +174,12 @@ func (c *mcentral) cacheSpan() *mspan {
 
        // At this point s is a span that should have free slots.
 havespan:
-       if traceEnabled() && !traceDone {
-               traceGCSweepDone()
+       if !traceDone {
+               trace := traceAcquire()
+               if trace.ok() {
+                       trace.GCSweepDone()
+                       traceRelease(trace)
+               }
        }
        n := int(s.nelems) - int(s.allocCount)
        if n == 0 || s.freeindex == s.nelems || s.allocCount == s.nelems {