]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert ncgocall to atomic type
authorcuiweixie <cuiweixie@gmail.com>
Sat, 27 Aug 2022 01:45:15 +0000 (09:45 +0800)
committerMichael Pratt <mpratt@google.com>
Thu, 1 Sep 2022 18:02:28 +0000 (18:02 +0000)
For #53821

Change-Id: Ib0d62ee36487b3ed68e063976968f3cac6499e4b
Reviewed-on: https://go-review.googlesource.com/c/go/+/426075
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/runtime/cgocall.go
src/runtime/debug.go
src/runtime/proc.go

index 0a25cb65629023eb76d3d7076d8b394cd2c81320..9d6568b2923678fad635440970e4d5aac4563703 100644 (file)
@@ -111,7 +111,7 @@ func syscall_cgocaller(fn unsafe.Pointer, args ...uintptr) uintptr {
        return as.retval
 }
 
-var ncgocall uint64 // number of cgo calls in total for dead m
+var ncgocall atomic.Uint64 // number of cgo calls in total for dead m
 
 // Call from Go to C.
 //
index 669c36f0d584bd7e2d464a893c6afc92f45c4cfa..531c316b977ae5f6ea956411a05c4b80ea851be3 100644 (file)
@@ -45,7 +45,7 @@ func NumCPU() int {
 
 // NumCgoCall returns the number of cgo calls made by the current process.
 func NumCgoCall() int64 {
-       var n = int64(atomic.Load64(&ncgocall))
+       var n = int64(ncgocall.Load())
        for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
                n += int64(mp.ncgocall)
        }
index 6ecb786d1b053c12efe7a170dc6ff68550399ba0..89cb5c70f0967e6708509a7edceba88da9f5f3fd 100644 (file)
@@ -1530,7 +1530,7 @@ found:
        }
        unlock(&sched.lock)
 
-       atomic.Xadd64(&ncgocall, int64(mp.ncgocall))
+       ncgocall.Add(int64(mp.ncgocall))
 
        // Release the P.
        handoffp(releasep())