From 5a6db7c48fb8a1e7b6d8f59ba4e3b7ecb8c35fc7 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Sat, 27 Aug 2022 09:45:15 +0800 Subject: [PATCH] runtime: convert ncgocall to atomic type For #53821 Change-Id: Ib0d62ee36487b3ed68e063976968f3cac6499e4b Reviewed-on: https://go-review.googlesource.com/c/go/+/426075 Reviewed-by: Michael Pratt Run-TryBot: xie cui <523516579@qq.com> Reviewed-by: Heschi Kreinick TryBot-Result: Gopher Robot --- src/runtime/cgocall.go | 2 +- src/runtime/debug.go | 2 +- src/runtime/proc.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go index 0a25cb65629..9d6568b2923 100644 --- a/src/runtime/cgocall.go +++ b/src/runtime/cgocall.go @@ -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. // diff --git a/src/runtime/debug.go b/src/runtime/debug.go index 669c36f0d58..531c316b977 100644 --- a/src/runtime/debug.go +++ b/src/runtime/debug.go @@ -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) } diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 6ecb786d1b0..89cb5c70f09 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -1530,7 +1530,7 @@ found: } unlock(&sched.lock) - atomic.Xadd64(&ncgocall, int64(mp.ncgocall)) + ncgocall.Add(int64(mp.ncgocall)) // Release the P. handoffp(releasep())