Skip to content

Commit

Permalink
runtime: make ncgocall a global counter
Browse files Browse the repository at this point in the history
ncgocall was stored per M, runtime.NumCgoCall lost the counter when a M die.

Fixes golang#46789
  • Loading branch information
qingyunha committed Jun 22, 2021
1 parent fb1d285 commit cbc15fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/runtime/debug.go
Expand Up @@ -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(ncgocall)
var n = int64(atomic.Load64(&ncgocall))
for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
n += int64(mp.ncgocall)
}
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/proc.go
Expand Up @@ -1507,7 +1507,6 @@ func mexit(osStack bool) {
}
throw("m not found in allm")
found:
ncgocall += m.ncgocall
if !osStack {
// Delay reaping m until it's done with the stack.
//
Expand All @@ -1523,6 +1522,8 @@ found:
}
unlock(&sched.lock)

atomic.Xadd64(&ncgocall, int64(m.ncgocall))

// Release the P.
handoffp(releasep())
// After this point we must not have write barriers.
Expand Down

0 comments on commit cbc15fa

Please sign in to comment.