Skip to content
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

bitswap: messagequeue: lock only needed sections #787

Merged
merged 1 commit into from
Jan 15, 2025
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
10 changes: 7 additions & 3 deletions bitswap/client/internal/messagequeue/messagequeue.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ func (mq *MessageQueue) AddBroadcastWantHaves(wantHaves []cid.Cid) {
}

mq.wllock.Lock()
defer mq.wllock.Unlock()

for _, c := range wantHaves {
mq.bcstWants.Add(c, mq.priority, pb.Message_Wantlist_Have)
Expand All @@ -329,6 +328,8 @@ func (mq *MessageQueue) AddBroadcastWantHaves(wantHaves []cid.Cid) {
mq.cancels.Remove(c)
}

mq.wllock.Unlock()

// Schedule a message send
mq.signalWorkReady()
}
Expand All @@ -340,7 +341,6 @@ func (mq *MessageQueue) AddWants(wantBlocks []cid.Cid, wantHaves []cid.Cid) {
}

mq.wllock.Lock()
defer mq.wllock.Unlock()

for _, c := range wantHaves {
mq.peerWants.Add(c, mq.priority, pb.Message_Wantlist_Have)
Expand All @@ -359,6 +359,8 @@ func (mq *MessageQueue) AddWants(wantBlocks []cid.Cid, wantHaves []cid.Cid) {
mq.cancels.Remove(c)
}

mq.wllock.Unlock()

// Schedule a message send
mq.signalWorkReady()
}
Expand Down Expand Up @@ -844,7 +846,6 @@ FINISH:
now := mq.clock.Now()

mq.wllock.Lock()
defer mq.wllock.Unlock()

for _, e := range peerEntries[:sentPeerEntries] {
if e.Cid.Defined() { // Check if want was canceled in the interim
Expand All @@ -857,6 +858,9 @@ FINISH:
mq.bcstWants.SentAt(e.Cid, now)
}
}

mq.wllock.Unlock()

if mq.events != nil {
mq.events <- messageFinishedSending
}
Expand Down
Loading