2010-06-21 21:53:49 -06:00
|
|
|
// 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
|
|
|
|
|
2014-08-28 08:46:59 -06:00
|
|
|
import "unsafe"
|
|
|
|
|
2010-06-21 21:53:49 -06:00
|
|
|
// 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.
|
2012-01-12 11:06:50 -07:00
|
|
|
// The number of logical CPUs on the local machine can be queried with NumCPU.
|
2010-06-21 21:53:49 -06:00
|
|
|
// This call will go away when the scheduler improves.
|
2014-08-28 08:46:59 -06:00
|
|
|
func GOMAXPROCS(n int) int {
|
2014-09-16 18:26:16 -06:00
|
|
|
if n > _MaxGomaxprocs {
|
|
|
|
n = _MaxGomaxprocs
|
|
|
|
}
|
|
|
|
lock(&sched.lock)
|
|
|
|
ret := int(gomaxprocs)
|
|
|
|
unlock(&sched.lock)
|
|
|
|
if n <= 0 || n == ret {
|
|
|
|
return ret
|
|
|
|
}
|
2014-08-28 08:46:59 -06:00
|
|
|
|
2015-05-15 14:00:50 -06:00
|
|
|
stopTheWorld("GOMAXPROCS")
|
2014-09-16 18:26:16 -06:00
|
|
|
|
2015-05-15 14:00:50 -06:00
|
|
|
// newprocs will be processed by startTheWorld
|
2014-09-16 18:26:16 -06:00
|
|
|
newprocs = int32(n)
|
|
|
|
|
2015-05-15 14:00:50 -06:00
|
|
|
startTheWorld()
|
2014-09-16 18:26:16 -06:00
|
|
|
return ret
|
|
|
|
}
|
2010-06-21 21:53:49 -06:00
|
|
|
|
2015-07-10 07:20:51 -06:00
|
|
|
// NumCPU returns the number of logical CPUs usable by the current process.
|
2014-08-28 08:46:59 -06:00
|
|
|
func NumCPU() int {
|
|
|
|
return int(ncpu)
|
|
|
|
}
|
2012-01-24 20:13:11 -07:00
|
|
|
|
2012-02-16 14:49:41 -07:00
|
|
|
// NumCgoCall returns the number of cgo calls made by the current process.
|
2014-08-28 08:46:59 -06:00
|
|
|
func NumCgoCall() int64 {
|
|
|
|
var n int64
|
|
|
|
for mp := (*m)(atomicloadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
|
|
|
|
n += int64(mp.ncgocall)
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
2010-06-21 21:53:49 -06:00
|
|
|
|
2012-02-16 14:49:41 -07:00
|
|
|
// NumGoroutine returns the number of goroutines that currently exist.
|
2014-08-28 08:46:59 -06:00
|
|
|
func NumGoroutine() int {
|
|
|
|
return int(gcount())
|
|
|
|
}
|