Skip to content
This repository was archived by the owner on Jan 4, 2026. It is now read-only.

Commit 3e5a45d

Browse files
committed
Correct logic of Critical Section coordination
Previously, we did not mark read/write grants as active. This was both unsound, and also did not work, because when releasing grants, we would notice the grants were not active and then ignore the commit/release. This was a bad transliteration of CAS to CS.
1 parent efa5f8d commit 3e5a45d

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bbq2"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
description = "A SPSC, lockless, no_std, thread safe, queue, based on BipBuffers"
55
repository = "https://github.com/jamesmunns/bbq2"
66
authors = ["James Munns <james@onevariable.com>"]

src/traits/coordination/cs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ unsafe impl Coord for CsCoord {
7676
if self.write_in_progress.load(Ordering::Relaxed) {
7777
return Err(WriteGrantError::GrantInProgress);
7878
}
79+
self.write_in_progress.store(true, Ordering::Relaxed);
7980

8081
// Writer component. Must never write to `read`,
8182
// be careful writing to `load`
@@ -132,6 +133,7 @@ unsafe impl Coord for CsCoord {
132133
if self.write_in_progress.load(Ordering::Relaxed) {
133134
return Err(WriteGrantError::GrantInProgress);
134135
}
136+
self.write_in_progress.store(true, Ordering::Relaxed);
135137

136138
// Writer component. Must never write to `read`,
137139
// be careful writing to `load`
@@ -183,6 +185,7 @@ unsafe impl Coord for CsCoord {
183185
if self.read_in_progress.load(Ordering::Relaxed) {
184186
return Err(ReadGrantError::GrantInProgress);
185187
}
188+
self.read_in_progress.store(true, Ordering::Relaxed);
186189

187190
let write = self.write.load(Ordering::Relaxed);
188191
let last = self.last.load(Ordering::Relaxed);
@@ -287,8 +290,8 @@ unsafe impl Coord for CsCoord {
287290

288291
// This should be fine, purely incrementing
289292
let old_read = self.read.load(Ordering::Relaxed);
290-
self.read.store(used + old_read, Ordering::Release);
291-
self.read_in_progress.store(false, Ordering::Release);
293+
self.read.store(used + old_read, Ordering::Relaxed);
294+
self.read_in_progress.store(false, Ordering::Relaxed);
292295
})
293296
}
294297
}

0 commit comments

Comments
 (0)