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"
|
|
|
|
|
2012-11-16 05:09:37 -07:00
|
|
|
// Breakpoint executes a breakpoint trap.
|
2010-06-21 21:53:49 -06:00
|
|
|
func Breakpoint()
|
|
|
|
|
|
|
|
// LockOSThread wires the calling goroutine to its current operating system thread.
|
|
|
|
// Until the calling goroutine exits or calls UnlockOSThread, it will always
|
|
|
|
// execute in that thread, and no other goroutine can.
|
|
|
|
func LockOSThread()
|
|
|
|
|
|
|
|
// UnlockOSThread unwires the calling goroutine from its fixed operating system thread.
|
|
|
|
// If the calling goroutine has not called LockOSThread, UnlockOSThread is a no-op.
|
|
|
|
func UnlockOSThread()
|
|
|
|
|
|
|
|
// 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-03 22:54:06 -06:00
|
|
|
g := getg()
|
|
|
|
g.m.scalararg[0] = uintptr(n)
|
|
|
|
onM(gomaxprocs_m)
|
|
|
|
n = int(g.m.scalararg[0])
|
|
|
|
g.m.scalararg[0] = 0
|
|
|
|
return n
|
2014-08-28 08:46:59 -06:00
|
|
|
}
|
|
|
|
|
2014-09-03 22:54:06 -06:00
|
|
|
func gomaxprocs_m() // proc.c
|
2010-06-21 21:53:49 -06:00
|
|
|
|
2012-01-24 20:13:11 -07:00
|
|
|
// NumCPU returns the number of logical CPUs on the local machine.
|
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())
|
|
|
|
}
|
|
|
|
|
|
|
|
func gcount() int32
|