Skip to content

FEATURE: [max] unlock depth buffer after emit #1857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
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
12 changes: 6 additions & 6 deletions pkg/depth/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (b *Buffer) SetUpdateTimeout(d time.Duration) {
}

func (b *Buffer) resetSnapshot() {
log.Info("resetting the snapshot")
b.snapshot = nil
b.finalUpdateID = 0
}
Expand Down Expand Up @@ -91,16 +92,16 @@ func (b *Buffer) SetSnapshot(snapshot types.SliceOrderBook, firstUpdateID int64,
return nil
}

log.Info("setting the snapshot")
// set the final update ID so that we will know if there is an update missing
b.finalUpdateID = finalUpdateID

// set the snapshot
b.snapshot = &snapshot
b.EmitReady(snapshot, nil)
Copy link
Owner

Choose a reason for hiding this comment

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

could be dangerous here, dead lock can happen


b.mu.Unlock()

// should unlock first then call ready
b.EmitReady(snapshot, nil)
return nil
}

Expand Down Expand Up @@ -176,10 +177,10 @@ func (b *Buffer) AddUpdate(o types.SliceOrderBook, firstUpdateID int64, finalArg

log.Debugf("depth update id %d -> %d", b.finalUpdateID, u.FinalUpdateID)
b.finalUpdateID = u.FinalUpdateID
b.mu.Unlock()

b.EmitPush(u)

b.mu.Unlock()

return nil
}

Expand Down Expand Up @@ -243,10 +244,9 @@ func (b *Buffer) fetchAndPush() error {

// set the snapshot
b.snapshot = &book
b.EmitReady(book, pushUpdates)

b.mu.Unlock()

// should unlock first then call ready
b.EmitReady(book, pushUpdates)
return nil
}
Loading