12345678910111213141516171819202122232425 |
- package gls
- var (
- stackTagPool = &idPool{}
- )
- func GetGoroutineId() (gid uint, ok bool) {
- return readStackTag()
- }
- func EnsureGoroutineId(cb func(gid uint)) {
- if gid, ok := readStackTag(); ok {
- cb(gid)
- return
- }
- gid := stackTagPool.Acquire()
- defer stackTagPool.Release(gid)
- addStackTag(gid, func() { cb(gid) })
- }
|