Skip to content

Commit

Permalink
chore: not expose goroutine id
Browse files Browse the repository at this point in the history
  • Loading branch information
joway committed May 14, 2024
1 parent c1b5f88 commit 472aacd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/utils/ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *Ring) Push(obj interface{}) error {
return r.rings[0].Push(obj)
}

idx := GoroutineID() % r.length
idx := getGoroutineID() % r.length
for i := 0; i < r.length; i, idx = i+1, (idx+1)%r.length {
err := r.rings[idx].Push(obj)
if err == nil {
Expand All @@ -80,7 +80,7 @@ func (r *Ring) Pop() interface{} {
return r.rings[0].Pop()
}

idx := GoroutineID() % r.length
idx := getGoroutineID() % r.length
for i := 0; i < r.length; i, idx = i+1, (idx+1)%r.length {
obj := r.rings[idx].Pop()
if obj != nil {
Expand All @@ -94,7 +94,7 @@ func (r *Ring) Pop() interface{} {
func (r *Ring) Dump() interface{} {
m := &ringDump{}
dumpList := make([]*ringDump, 0, r.length)
idx := GoroutineID() % r.length
idx := getGoroutineID() % r.length
for i := 0; i < r.length; i, idx = i+1, (idx+1)%r.length {
curDump := &ringDump{}
r.rings[idx].Dump(curDump)
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/runtimex.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"github.com/cloudwego/runtimex"
)

// GoroutineID return current G's ID, it will fall back to get a random int
func GoroutineID() int {
// getGoroutineID return current G's ID, it will fall back to get a random int
func getGoroutineID() int {
gid, err := runtimex.GID()
if err != nil {
gid = fastrand.Int()
Expand Down

0 comments on commit 472aacd

Please sign in to comment.