github.com/xg0n/routine@v0.0.0-20240119033701-c364deb94aee/g/g.go (about)

     1  // Copyright 2021-2024 TimAndy. All rights reserved.
     2  // Licensed under the Apache-2.0 license that can be found in the LICENSE file.
     3  
     4  package g
     5  
     6  import (
     7  	"reflect"
     8  	"unsafe"
     9  )
    10  
    11  // g0 the value of runtime.g0.
    12  //
    13  //go:linkname g0 runtime.g0
    14  var g0 struct{}
    15  
    16  // getgp returns the pointer to the current runtime.g.
    17  //
    18  //go:nosplit
    19  func getgp() unsafe.Pointer
    20  
    21  // getg0 returns the value of runtime.g0.
    22  //
    23  //go:nosplit
    24  func getg0() interface{} {
    25  	return packEface(getgt(), unsafe.Pointer(&g0))
    26  }
    27  
    28  // getgt returns the type of runtime.g.
    29  //
    30  //go:nosplit
    31  func getgt() reflect.Type {
    32  	return typeByString("runtime.g")
    33  }