]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/runtime/mgcpacer.go
runtime: refactor runtime->tracer API to appear more like a lock
[gostls13.git] / src / runtime / mgcpacer.go
index 10767df26c72501d1d782b4d3c8118307587a75c..716e3efcccebba33414183211a6784a3bb2c5ef9 100644 (file)
@@ -807,9 +807,11 @@ func (c *gcControllerState) findRunnableGCWorker(pp *p, now int64) (*g, int64) {
 
        // Run the background mark worker.
        gp := node.gp.ptr()
+       trace := traceAcquire()
        casgstatus(gp, _Gwaiting, _Grunnable)
-       if traceEnabled() {
-               traceGoUnpark(gp, 0)
+       if trace.ok() {
+               trace.GoUnpark(gp, 0)
+               traceRelease(trace)
        }
        return gp, now
 }
@@ -828,8 +830,10 @@ func (c *gcControllerState) resetLive(bytesMarked uint64) {
        c.triggered = ^uint64(0) // Reset triggered.
 
        // heapLive was updated, so emit a trace event.
-       if traceEnabled() {
-               traceHeapAlloc(bytesMarked)
+       trace := traceAcquire()
+       if trace.ok() {
+               trace.HeapAlloc(bytesMarked)
+               traceRelease(trace)
        }
 }
 
@@ -856,10 +860,12 @@ func (c *gcControllerState) markWorkerStop(mode gcMarkWorkerMode, duration int64
 
 func (c *gcControllerState) update(dHeapLive, dHeapScan int64) {
        if dHeapLive != 0 {
+               trace := traceAcquire()
                live := gcController.heapLive.Add(dHeapLive)
-               if traceEnabled() {
+               if trace.ok() {
                        // gcController.heapLive changed.
-                       traceHeapAlloc(live)
+                       trace.HeapAlloc(live)
+                       traceRelease(trace)
                }
        }
        if gcBlackenEnabled == 0 {
@@ -1428,8 +1434,10 @@ func gcControllerCommit() {
 
        // TODO(mknyszek): This isn't really accurate any longer because the heap
        // goal is computed dynamically. Still useful to snapshot, but not as useful.
-       if traceEnabled() {
-               traceHeapGoal()
+       trace := traceAcquire()
+       if trace.ok() {
+               trace.HeapGoal()
+               traceRelease(trace)
        }
 
        trigger, heapGoal := gcController.trigger()