github.com/suiyunonghen/DxCommonLib@v0.5.3/system/goid/goid.go (about) 1 package goid 2 3 import ( 4 "reflect" 5 "unsafe" 6 ) 7 8 const GoId = "goid" 9 10 type eface struct { 11 typ, val unsafe.Pointer 12 } 13 14 //go:nosplit 15 func runtime_convT2E_hack(_type, elem unsafe.Pointer) eface { 16 return eface{ 17 typ: _type, 18 val: elem, 19 } 20 } 21 22 var offset int64 23 24 func init() { 25 offset = func() int64 { 26 g := getG() 27 if f, ok := reflect.TypeOf(g).FieldByName(GoId); ok { 28 return int64(f.Offset) 29 } 30 panic("can not find g.goid field") 31 }() 32 33 } 34 35 func getG() interface{} 36 37 // GetGoID return current goroutine id. 38 func GetGoID() int64