github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/internal/runtimex/ppin.go (about)

     1  package runtimex
     2  
     3  import (
     4  	_ "unsafe"
     5  )
     6  
     7  //go:noescape
     8  //go:linkname runtime_procPin runtime.procPin
     9  func runtime_procPin() int
    10  
    11  //go:noescape
    12  //go:linkname runtime_procUnpin runtime.procUnpin
    13  func runtime_procUnpin()
    14  
    15  // Pin pins current p, return pid.
    16  // DO NOT USE if you don't know what this is.
    17  func Pin() int {
    18  	return runtime_procPin()
    19  }
    20  
    21  // Unpin unpins current p.
    22  func Unpin() {
    23  	runtime_procUnpin()
    24  }
    25  
    26  // Pid returns the id of current p.
    27  func Pid() (id int) {
    28  	id = runtime_procPin()
    29  	runtime_procUnpin()
    30  	return
    31  }