2010-12-03 05:34:57 +01: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
|
|
|
|
|
2016-11-16 19:33:11 +01:00
|
|
|
import (
|
|
|
|
"runtime/internal/atomic"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
// GOMAXPROCS sets the maximum number of CPUs that can be executing
|
2016-07-22 20:15:38 +02:00
|
|
|
// simultaneously and returns the previous setting. If n < 1, it does not
|
2010-12-03 05:34:57 +01:00
|
|
|
// change the current setting.
|
2012-01-25 21:56:26 +01:00
|
|
|
// The number of logical CPUs on the local machine can be queried with NumCPU.
|
2010-12-03 05:34:57 +01:00
|
|
|
// This call will go away when the scheduler improves.
|
2017-01-09 20:37:19 +01:00
|
|
|
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
|
|
|
|
}
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2016-02-03 22:58:02 +01:00
|
|
|
// NumCPU returns the number of logical CPUs usable by the current process.
|
|
|
|
//
|
|
|
|
// The set of available CPUs is checked by querying the operating system
|
|
|
|
// at process startup. Changes to operating system CPU allocation after
|
|
|
|
// process startup are not reflected.
|
2012-02-01 20:26:59 +01:00
|
|
|
func NumCPU() int
|
|
|
|
|
2012-03-02 21:01:37 +01:00
|
|
|
// NumCgoCall returns the number of cgo calls made by the current process.
|
2016-11-16 19:33:11 +01:00
|
|
|
func NumCgoCall() int64 {
|
|
|
|
var n int64
|
2017-01-10 22:09:00 +01:00
|
|
|
for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
|
2016-11-16 19:33:11 +01:00
|
|
|
n += int64(mp.ncgocall)
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2012-03-02 21:01:37 +01:00
|
|
|
// NumGoroutine returns the number of goroutines that currently exist.
|
2016-11-16 19:33:11 +01:00
|
|
|
func NumGoroutine() int {
|
|
|
|
return int(gcount())
|
|
|
|
}
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2012-11-29 19:11:17 +01:00
|
|
|
// Get field tracking information. Only fields with a tag go:"track"
|
|
|
|
// are tracked. This function will add every such field that is
|
|
|
|
// referenced to the map. The keys in the map will be
|
|
|
|
// PkgPath.Name.FieldName. The value will be true for each field
|
|
|
|
// added.
|
|
|
|
func Fieldtrack(map[string]bool)
|