mirror of
https://github.com/golang/go
synced 2024-11-08 18:26:14 -07:00
2de67e9974
Update #11609. Change-Id: Ie363facf13f5e62f1af4a8bdc42a18fb36e16ebf Reviewed-on: https://go-review.googlesource.com/12022 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package runtime
|
|
|
|
import "unsafe"
|
|
|
|
// GOMAXPROCS sets the maximum number of CPUs that can be executing
|
|
// simultaneously and returns the previous setting. If n < 1, it does not
|
|
// change the current setting.
|
|
// The number of logical CPUs on the local machine can be queried with NumCPU.
|
|
// This call will go away when the scheduler improves.
|
|
func GOMAXPROCS(n int) int {
|
|
if n > _MaxGomaxprocs {
|
|
n = _MaxGomaxprocs
|
|
}
|
|
lock(&sched.lock)
|
|
ret := int(gomaxprocs)
|
|
unlock(&sched.lock)
|
|
if n <= 0 || n == ret {
|
|
return ret
|
|
}
|
|
|
|
stopTheWorld("GOMAXPROCS")
|
|
|
|
// newprocs will be processed by startTheWorld
|
|
newprocs = int32(n)
|
|
|
|
startTheWorld()
|
|
return ret
|
|
}
|
|
|
|
// NumCPU returns the number of logical CPUs usable by the current process.
|
|
func NumCPU() int {
|
|
return int(ncpu)
|
|
}
|
|
|
|
// NumCgoCall returns the number of cgo calls made by the current process.
|
|
func NumCgoCall() int64 {
|
|
var n int64
|
|
for mp := (*m)(atomicloadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
|
|
n += int64(mp.ncgocall)
|
|
}
|
|
return n
|
|
}
|
|
|
|
// NumGoroutine returns the number of goroutines that currently exist.
|
|
func NumGoroutine() int {
|
|
return int(gcount())
|
|
}
|