1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package runtime
6
7import (
8	"runtime/internal/atomic"
9	"unsafe"
10)
11
12// GOMAXPROCS sets the maximum number of CPUs that can be executing
13// simultaneously and returns the previous setting. If n < 1, it does not
14// change the current setting.
15// The number of logical CPUs on the local machine can be queried with NumCPU.
16// This call will go away when the scheduler improves.
17func GOMAXPROCS(n int) int {
18	lock(&sched.lock)
19	ret := int(gomaxprocs)
20	unlock(&sched.lock)
21	if n <= 0 || n == ret {
22		return ret
23	}
24
25	stopTheWorld("GOMAXPROCS")
26
27	// newprocs will be processed by startTheWorld
28	newprocs = int32(n)
29
30	startTheWorld()
31	return ret
32}
33
34// NumCPU returns the number of logical CPUs usable by the current process.
35//
36// The set of available CPUs is checked by querying the operating system
37// at process startup. Changes to operating system CPU allocation after
38// process startup are not reflected.
39func NumCPU() int {
40	return int(ncpu)
41}
42
43// NumCgoCall returns the number of cgo calls made by the current process.
44func NumCgoCall() int64 {
45	var n int64
46	for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
47		n += int64(mp.ncgocall)
48	}
49	return n
50}
51
52// NumGoroutine returns the number of goroutines that currently exist.
53func NumGoroutine() int {
54	waitForSystemGoroutines()
55	return int(gcount())
56}
57
58// Get field tracking information.  Only fields with a tag go:"track"
59// are tracked.  This function will add every such field that is
60// referenced to the map.  The keys in the map will be
61// PkgPath.Name.FieldName.  The value will be true for each field
62// added.
63func Fieldtrack(map[string]bool)
64