runtime: copy more scheduler code from Go 1.7 runtime
[official-gcc.git] / libgo / go / runtime / debug.go
bloba8827f20b2abb175f2ce1f140ebc5b8e9b3a9fb9
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.
5 package runtime
7 import (
8 "runtime/internal/atomic"
9 "unsafe"
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.
17 func GOMAXPROCS(n int) int {
18 if n > _MaxGomaxprocs {
19 n = _MaxGomaxprocs
21 lock(&sched.lock)
22 ret := int(gomaxprocs)
23 unlock(&sched.lock)
24 if n <= 0 || n == ret {
25 return ret
28 stopTheWorld("GOMAXPROCS")
30 // newprocs will be processed by startTheWorld
31 newprocs = int32(n)
33 startTheWorld()
34 return ret
37 // NumCPU returns the number of logical CPUs usable by the current process.
39 // The set of available CPUs is checked by querying the operating system
40 // at process startup. Changes to operating system CPU allocation after
41 // process startup are not reflected.
42 func NumCPU() int
44 // NumCgoCall returns the number of cgo calls made by the current process.
45 func NumCgoCall() int64 {
46 var n int64
47 for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
48 n += int64(mp.ncgocall)
50 return n
53 // NumGoroutine returns the number of goroutines that currently exist.
54 func NumGoroutine() int {
55 return int(gcount())
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.
63 func Fieldtrack(map[string]bool)