...
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	// Breakpoint executes a breakpoint trap.
    10	func Breakpoint()
    11	
    12	// LockOSThread wires the calling goroutine to its current operating system thread.
    13	// Until the calling goroutine exits or calls UnlockOSThread, it will always
    14	// execute in that thread, and no other goroutine can.
    15	func LockOSThread()
    16	
    17	// UnlockOSThread unwires the calling goroutine from its fixed operating system thread.
    18	// If the calling goroutine has not called LockOSThread, UnlockOSThread is a no-op.
    19	func UnlockOSThread()
    20	
    21	// GOMAXPROCS sets the maximum number of CPUs that can be executing
    22	// simultaneously and returns the previous setting.  If n < 1, it does not
    23	// change the current setting.
    24	// The number of logical CPUs on the local machine can be queried with NumCPU.
    25	// This call will go away when the scheduler improves.
    26	func GOMAXPROCS(n int) int {
    27		if n > _MaxGomaxprocs {
    28			n = _MaxGomaxprocs
    29		}
    30		lock(&sched.lock)
    31		ret := int(gomaxprocs)
    32		unlock(&sched.lock)
    33		if n <= 0 || n == ret {
    34			return ret
    35		}
    36	
    37		semacquire(&worldsema, false)
    38		gp := getg()
    39		gp.m.gcing = 1
    40		onM(stoptheworld)
    41	
    42		// newprocs will be processed by starttheworld
    43		newprocs = int32(n)
    44	
    45		gp.m.gcing = 0
    46		semrelease(&worldsema)
    47		onM(starttheworld)
    48		return ret
    49	}
    50	
    51	// NumCPU returns the number of logical CPUs on the local machine.
    52	func NumCPU() int {
    53		return int(ncpu)
    54	}
    55	
    56	// NumCgoCall returns the number of cgo calls made by the current process.
    57	func NumCgoCall() int64 {
    58		var n int64
    59		for mp := (*m)(atomicloadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
    60			n += int64(mp.ncgocall)
    61		}
    62		return n
    63	}
    64	
    65	// NumGoroutine returns the number of goroutines that currently exist.
    66	func NumGoroutine() int {
    67		return int(gcount())
    68	}
    69	
    70	func gcount() int32
    71	

View as plain text