Skip to content

Commit 40e9756

Browse files
loganjLarryclaude
committed
fix(clipboard): keep the expiry read's flag when a second read is refused
Reading::begin built its guard eagerly with then_some, so a refused admission dropped a guard whose Drop cleared the flag the running read still held, and the next read was admitted. The guard now exists only after the flag is taken. The test checks two refusals in a row. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Logan Johnson <[email protected]>
1 parent f11bfae commit 40e9756

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎src-tauri/src/clipboard.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,14 @@ static READING: AtomicBool = AtomicBool::new(false);
152152
/// Holds `READING` until dropped.
153153
struct Reading(&'static AtomicBool);
154154
impl Reading {
155-
/// `None` while another read holds `flag`.
155+
/// `None` while another read holds `flag`. A guard exists only once the
156+
/// flag is taken, so a refusal leaves the holder's flag set.
156157
fn begin(flag: &'static AtomicBool) -> Option<Self> {
157-
(!flag.swap(true, Ordering::SeqCst)).then_some(Self(flag))
158+
if flag.swap(true, Ordering::SeqCst) {
159+
None
160+
} else {
161+
Some(Self(flag))
162+
}
158163
}
159164
}
160165
impl Drop for Reading {
@@ -319,6 +324,8 @@ mod tests {
319324
fn only_one_expiry_read_runs_at_a_time() {
320325
static FLAG: AtomicBool = AtomicBool::new(false);
321326
let stuck = Reading::begin(&FLAG).unwrap();
327+
// A refused admission must not release the read that holds the flag.
328+
assert!(Reading::begin(&FLAG).is_none());
322329
assert!(Reading::begin(&FLAG).is_none());
323330
drop(stuck);
324331
assert!(Reading::begin(&FLAG).is_some());

0 commit comments

Comments
 (0)