mirror of
https://github.com/golang/go
synced 2024-11-08 05:46:12 -07:00
35ea62468b
This commit adds the js/wasm architecture to the runtime package. Currently WebAssembly has no support for threads yet, see https://github.com/WebAssembly/design/issues/1073. Because of that, there is no preemption of goroutines and no sysmon goroutine. Design doc: https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0_Nv3OUwjEY5qVCxCup4 About WebAssembly assembly files: https://docs.google.com/document/d/1GRmy3rA4DiYtBlX-I1Jr_iHykbX8EixC3Mq0TCYqbKc Updates #18892 Change-Id: I7f12d21b5180500d55ae9fd2f7e926a1731db391 Reviewed-on: https://go-review.googlesource.com/103877 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
60 lines
1.5 KiB
Go
60 lines
1.5 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. If n < 1, it does not
|
|
// change the current setting.
|
|
// The number of logical CPUs on the local machine can be queried with NumCPU.
|
|
// 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
|
|
}
|
|
|
|
stopTheWorld("GOMAXPROCS")
|
|
|
|
// newprocs will be processed by startTheWorld
|
|
newprocs = int32(n)
|
|
|
|
startTheWorld()
|
|
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())
|
|
}
|