Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

lockless version of defaultIDGenerator.NewSpanID #851

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,10 @@ type defaultIDGenerator struct {
// NewSpanID returns a non-zero span ID from a randomly-chosen sequence.
// mu should be held while this function is called.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this statement still true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing, removing it.

func (gen *defaultIDGenerator) NewSpanID() [8]byte {
gen.Lock()
id := gen.nextSpanID
gen.nextSpanID += gen.spanIDInc
if gen.nextSpanID == 0 {
gen.nextSpanID += gen.spanIDInc
var id uint64
for id == 0 {
id = atomic.AddUint64(&gen.nextSpanID, gen.spanIDInc)
}
gen.Unlock()
var sid [8]byte
binary.LittleEndian.PutUint64(sid[:], id)
return sid
Expand Down