qoobing.com/gomod/log@v1.2.8/logid-runtime-patch/unknown/debug.go (about)

     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 (
     8  	"runtime/internal/atomic"
     9  	"unsafe"
    10  )
    11  
    12  // GOMAXPROCS sets the maximum number of CPUs that can be executing
    13  // simultaneously and returns the previous setting. If n < 1, it does not
    14  // change the current setting.
    15  // The number of logical CPUs on the local machine can be queried with NumCPU.
    16  // This call will go away when the scheduler improves.
    17  func GOMAXPROCS(n int) int {
    18  	if GOARCH == "wasm" && n > 1 {
    19  		n = 1 // WebAssembly has no threads yet, so only one CPU is possible.
    20  	}
    21  
    22  	lock(&sched.lock)
    23  	ret := int(gomaxprocs)
    24  	unlock(&sched.lock)
    25  	if n <= 0 || n == ret {
    26  		return ret
    27  	}
    28  
    29  	stopTheWorld("GOMAXPROCS")
    30  
    31  	// newprocs will be processed by startTheWorld
    32  	newprocs = int32(n)
    33  
    34  	startTheWorld()
    35  	return ret
    36  }
    37  
    38  // NumCPU returns the number of logical CPUs usable by the current process.
    39  //
    40  // The set of available CPUs is checked by querying the operating system
    41  // at process startup. Changes to operating system CPU allocation after
    42  // process startup are not reflected.
    43  func NumCPU() int {
    44  	return int(ncpu)
    45  }
    46  
    47  // NumCgoCall returns the number of cgo calls made by the current process.
    48  func NumCgoCall() int64 {
    49  	var n int64
    50  	for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
    51  		n += int64(mp.ncgocall)
    52  	}
    53  	return n
    54  }
    55  
    56  // NumGoroutine returns the number of goroutines that currently exist.
    57  func NumGoroutine() int {
    58  	return int(gcount())
    59  }
    60  
    61  // GetLogid get a goroutine log, the logid is setted by SetLogid,
    62  // or it is succesed from parents goroutine.
    63  // add for test by q.bryant@live.com @ 2020.09.10
    64  func GetLogid()int64{
    65       _g_ := getg()
    66       return _g_.logid
    67  }
    68  
    69  // SetLogid get a goroutine log, you can get the logid by GetLogid,
    70  // it will return the old logid for trace call stack.
    71  // add for test by q.bryant@live.com @ 2020.09.10
    72  func SetLogid(newid int64)(oldid int64){
    73       _g_ := getg()
    74       oldid = _g_.logid
    75       _g_.logid = newid
    76       return oldid
    77  }
    78  
    79  //go:linkname debug_modinfo runtime/debug.modinfo
    80  func debug_modinfo() string {
    81  	return modinfo
    82  }