mirror of
https://github.com/golang/go
synced 2024-11-07 12:26:16 -07:00
8098dbb30e
https://github.com/golang/go/blob/master/doc/effective_go.html#L3211 is used to update the docs comment for `GOMAXPROCS` function.
Fixes #41275
Change-Id: I39f58e93a267c6e9f3ac6638ed51acbe5284ada2
GitHub-Last-Rev: e45c8ac587
GitHub-Pull-Request: golang/go#41276
Reviewed-on: https://go-review.googlesource.com/c/go/+/253537
Reviewed-by: Keith Randall <khr@golang.org>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
// 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
|
|
|
|
import (
|
|
"runtime/internal/atomic"
|
|
"unsafe"
|
|
)
|
|
|
|
// GOMAXPROCS sets the maximum number of CPUs that can be executing
|
|
// simultaneously and returns the previous setting. It defaults to
|
|
// the value of runtime.NumCPU. If n < 1, it does not change the current setting.
|
|
// This call will go away when the scheduler improves.
|
|
func GOMAXPROCS(n int) int {
|
|
if GOARCH == "wasm" && n > 1 {
|
|
n = 1 // WebAssembly has no threads yet, so only one CPU is possible.
|
|
}
|
|
|
|
lock(&sched.lock)
|
|
ret := int(gomaxprocs)
|
|
unlock(&sched.lock)
|
|
if n <= 0 || n == ret {
|
|
return ret
|
|
}
|
|
|
|
stopTheWorldGC("GOMAXPROCS")
|
|
|
|
// newprocs will be processed by startTheWorld
|
|
newprocs = int32(n)
|
|
|
|
startTheWorldGC()
|
|
return ret
|
|
}
|
|
|
|
// 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.
|
|
func NumCPU() int {
|
|
return int(ncpu)
|
|
}
|
|
|
|
// NumCgoCall returns the number of cgo calls made by the current process.
|
|
func NumCgoCall() int64 {
|
|
var n int64
|
|
for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
|
|
n += int64(mp.ncgocall)
|
|
}
|
|
return n
|
|
}
|
|
|
|
// NumGoroutine returns the number of goroutines that currently exist.
|
|
func NumGoroutine() int {
|
|
return int(gcount())
|
|
}
|
|
|
|
//go:linkname debug_modinfo runtime/debug.modinfo
|
|
func debug_modinfo() string {
|
|
return modinfo
|
|
}
|