...
Run Format

Source file src/runtime/debug.go

     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	
     5	package runtime
     6	
     7	import "unsafe"
     8	
     9	// GOMAXPROCS sets the maximum number of CPUs that can be executing
    10	// simultaneously and returns the previous setting.  If n < 1, it does not
    11	// change the current setting.
    12	// The number of logical CPUs on the local machine can be queried with NumCPU.
    13	// This call will go away when the scheduler improves.
    14	func GOMAXPROCS(n int) int {
    15		if n > _MaxGomaxprocs {
    16			n = _MaxGomaxprocs
    17		}
    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	func NumCPU() int {
    36		return int(ncpu)
    37	}
    38	
    39	// NumCgoCall returns the number of cgo calls made by the current process.
    40	func NumCgoCall() int64 {
    41		var n int64
    42		for mp := (*m)(atomicloadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
    43			n += int64(mp.ncgocall)
    44		}
    45		return n
    46	}
    47	
    48	// NumGoroutine returns the number of goroutines that currently exist.
    49	func NumGoroutine() int {
    50		return int(gcount())
    51	}
    52	

View as plain text