github.com/sitano/gsysint@v0.0.0-20190607084937-69a4f3233e4e/g/g.go (about)

     1  // Package g provides access to the runtime structures of go1.12.5
     2  // that participate in organization of goroutines scheduling.
     3  //
     4  // On scheduling check:
     5  // - [scheduler](https://github.com/golang/go/blob/7bc40ffb05d8813bf9b41a331b45d37216f9e747/src/runtime/proc.go#L2022)
     6  // - [details](https://golang.org/s/go11sched)
     7  //
     8  // Mainly this package gives you an access to the G and P structures:
     9  // - G - goroutine.
    10  // - M - worker thread, or machine.
    11  // - P - processor, a resource that is required to execute Go code.
    12  //       M must have an associated P to execute Go code, however it can be
    13  //       blocked or in a syscall w/o an associated P.
    14  package g
    15  
    16  import "unsafe"
    17  
    18  // GetGPtr returns the pointer to the current g.
    19  // The compiler rewrites calls to this function into instructions
    20  // that fetch the g directly (from TLS or from the dedicated register).
    21  func GetG() unsafe.Pointer
    22  
    23  // GetMPtr returns the pointer to the current m.
    24  func GetM() unsafe.Pointer
    25  
    26  // CurG returns the pointer to the current g.
    27  // The compiler rewrites calls to this function into instructions
    28  // that fetch the g directly (from TLS or from the dedicated register).
    29  func CurG() *G {
    30  	return (*G)(GetG())
    31  }
    32  
    33  // CurM returns the pointer to the current m.
    34  func CurM() *M {
    35  	return (*M)(GetM())
    36  }