github.com/bytedance/gopkg@v0.0.0-20240514070511-01b2cbcf35e1/internal/runtimex/ppin.go (about)

     1  // Copyright 2021 ByteDance Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package runtimex
    16  
    17  import (
    18  	_ "unsafe"
    19  )
    20  
    21  //go:noescape
    22  //go:linkname runtime_procPin runtime.procPin
    23  func runtime_procPin() int
    24  
    25  //go:noescape
    26  //go:linkname runtime_procUnpin runtime.procUnpin
    27  func runtime_procUnpin()
    28  
    29  // Pin pins current p, return pid.
    30  // DO NOT USE if you don't know what this is.
    31  func Pin() int {
    32  	return runtime_procPin()
    33  }
    34  
    35  // Unpin unpins current p.
    36  func Unpin() {
    37  	runtime_procUnpin()
    38  }
    39  
    40  // Pid returns the id of current p.
    41  func Pid() (id int) {
    42  	id = runtime_procPin()
    43  	runtime_procUnpin()
    44  	return
    45  }