Skip to content
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
18 changes: 13 additions & 5 deletions nostr-sdk/src/relay/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,19 @@ impl PendingReqCounter {

#[inline]
fn decrement(&self) {
let _ = self
.0
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |count| {
count.checked_sub(1)
});
// Saturating decrement. Newer Rust deprecates `fetch_update` in favor of
// `try_update`, which is above the MSRV, so spell out its CAS loop.
let mut count: usize = self.0.load(Ordering::SeqCst);

while let Some(next) = count.checked_sub(1) {
match self
.0
.compare_exchange_weak(count, next, Ordering::SeqCst, Ordering::SeqCst)
{
Ok(_) => return,
Err(actual) => count = actual,
}
}
}

#[inline]
Expand Down
Loading