2 Star 2 Fork 8

王布衣/gox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
goid.go 637 Bytes
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-05-13 07:55 . 迁移代码仓库到gitee
package gls
import (
reflect "gitee.com/quant1x/gox/util/reflect2"
"unsafe"
)
var (
goidOffset uintptr = 128 // offset for go1.4
)
func init() {
gType := reflect.TypeByName("runtime.g").(reflect.StructType)
if gType == nil {
panic("failed to get runtime.g type")
}
goidField := gType.FieldByName("goid")
goidOffset = goidField.Offset()
}
// GoID returns the goroutine id of current goroutine
//
//go:nocheckptr
func GoID() int64 {
g := getg()
// TODO: fatal error: checkptr: pointer arithmetic result points to invalid allocation
p_goid := (*int64)(unsafe.Pointer(g + goidOffset))
return *p_goid
}
func getg() uintptr
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/gox.git
git@gitee.com:quant1x/gox.git
quant1x
gox
gox
v1.7.3

搜索帮助