From 6179aca54825867db3ab15bfff28fbda73e49378 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 28 Aug 2014 10:46:59 -0400 Subject: runtime: convert runtime1.goc, noasm_arm.goc to Go LGTM=dvyukov R=golang-codereviews, bradfitz, dvyukov CC=golang-codereviews, iant, khr https://golang.org/cl/135070043 --- src/pkg/runtime/debug.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/pkg/runtime/debug.go') diff --git a/src/pkg/runtime/debug.go b/src/pkg/runtime/debug.go index af44a64741..181fac4615 100644 --- a/src/pkg/runtime/debug.go +++ b/src/pkg/runtime/debug.go @@ -4,6 +4,8 @@ package runtime +import "unsafe" + // Breakpoint executes a breakpoint trap. func Breakpoint() @@ -21,16 +23,32 @@ func UnlockOSThread() // 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 +func GOMAXPROCS(n int) int { + return int(gomaxprocsfunc(int32(n))) +} + +func gomaxprocsfunc(int32) int32 // proc.c // NumCPU returns the number of logical CPUs on the local machine. -func NumCPU() int +func NumCPU() int { + return int(ncpu) +} // NumCgoCall returns the number of cgo calls made by the current process. -func NumCgoCall() int64 +func NumCgoCall() int64 { + var n int64 + for mp := (*m)(atomicloadp(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 +func NumGoroutine() int { + return int(gcount()) +} + +func gcount() int32 // MemProfileRate controls the fraction of memory allocations // that are recorded and reported in the memory profile. -- cgit v1.3-5-g9baa