Skip to content

Commit f45364d

Browse files
committed
Another one :(
1 parent 8119db2 commit f45364d

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

rtic-sync/checkpoint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"preemption_bound":null,"pos":0,"branches":{"entries":[{"Schedule":{"preemptions":0,"initial_active":0,"threads":["Active","Disabled","Disabled","Disabled","Disabled"],"prev":null,"exploring":true}},{"Schedule":{"preemptions":0,"initial_active":0,"threads":["Active","Disabled","Disabled","Disabled","Disabled"],"prev":{"index":0,"_p":null},"exploring":true}},{"Load":{"values":[0,0,0,0,0,0,0],"pos":0,"len":1,"exploring":true}},{"Schedule":{"preemptions":0,"initial_active":0,"threads":["Active","Disabled","Disabled","Disabled","Disabled"],"prev":{"index":1,"_p":null},"exploring":true}},{"Schedule":{"preemptions":0,"initial_active":0,"threads":["Active","Disabled","Disabled","Disabled","Disabled"],"prev":{"index":3,"_p":null},"exploring":true}},{"Schedule":{"preemptions":0,"initial_active":0,"threads":["Active","Disabled","Disabled","Disabled","Disabled"],"prev":{"index":4,"_p":null},"exploring":true}},{"Schedule":{"preemptions":0,"initial_active":0,"threads":["Active","Disabled","Disabled","Disabled","Disabled"],"prev":{"index":5,"_p":null},"exploring":true}},{"Schedule":{"preemptions":0,"initial_active":0,"threads":["Active","Pending","Skip","Disabled","Disabled"],"prev":{"index":6,"_p":null},"exploring":true}},{"Schedule":{"preemptions":0,"initial_active":0,"threads":["Visited","Active","Pending","Disabled","Disabled"],"prev":{"index":7,"_p":null},"exploring":true}},{"Schedule":{"preemptions":1,"initial_active":1,"threads":["Pending","Active","Skip","Disabled","Disabled"],"prev":{"index":8,"_p":null},"exploring":true}},{"Schedule":{"preemptions":1,"initial_active":1,"threads":["Disabled","Active","Skip","Disabled","Disabled"],"prev":{"index":9,"_p":null},"exploring":true}},{"Load":{"values":[0,0,0,0,0,0,0],"pos":0,"len":1,"exploring":true}},{"Schedule":{"preemptions":1,"initial_active":1,"threads":["Disabled","Active","Skip","Disabled","Disabled"],"prev":{"index":10,"_p":null},"exploring":true}},{"Load":{"values":[0,0,0,0,0,0,0],"pos":0,"len":1,"exploring":true}},{"Schedule":{"preemptions":1,"initial_active":1,"threads":["Disabled","Active","Skip","Disabled","Disabled"],"prev":{"index":12,"_p":null},"exploring":true}},{"Schedule":{"preemptions":1,"initial_active":1,"threads":["Disabled","Active","Pending","Disabled","Disabled"],"prev":{"index":14,"_p":null},"exploring":true}},{"Schedule":{"preemptions":1,"initial_active":1,"threads":["Active","Visited","Pending","Disabled","Disabled"],"prev":{"index":15,"_p":null},"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Disabled","Skip","Disabled","Disabled"],"prev":{"index":16,"_p":null},"exploring":true}},{"Load":{"values":[1,0,0,0,0,0,0],"pos":0,"len":1,"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Disabled","Skip","Disabled","Disabled"],"prev":{"index":17,"_p":null},"exploring":true}},{"Load":{"values":[0,0,0,0,0,0,0],"pos":0,"len":1,"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Disabled","Pending","Disabled","Disabled"],"prev":{"index":19,"_p":null},"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Disabled","Skip","Disabled","Disabled"],"prev":{"index":21,"_p":null},"exploring":true}},{"Load":{"values":[1,0,0,0,0,0,0],"pos":0,"len":1,"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Disabled","Skip","Disabled","Disabled"],"prev":{"index":22,"_p":null},"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Disabled","Skip","Disabled","Disabled"],"prev":{"index":24,"_p":null},"exploring":true}},{"Load":{"values":[0,0,0,0,0,0,0],"pos":0,"len":1,"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Disabled","Skip","Disabled","Disabled"],"prev":{"index":25,"_p":null},"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Disabled","Skip","Disabled","Disabled"],"prev":{"index":27,"_p":null},"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Disabled","Skip","Disabled","Disabled"],"prev":{"index":28,"_p":null},"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Pending","Skip","Disabled","Disabled"],"prev":{"index":29,"_p":null},"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Active","Pending","Pending","Disabled","Disabled"],"prev":{"index":30,"_p":null},"exploring":true}},{"Schedule":{"preemptions":2,"initial_active":0,"threads":["Visited","Visited","Active","Disabled","Disabled"],"prev":{"index":31,"_p":null},"exploring":true}},{"Schedule":{"preemptions":3,"initial_active":2,"threads":["Skip","Skip","Active","Disabled","Disabled"],"prev":{"index":32,"_p":null},"exploring":true}},{"Load":{"values":[0,1,2,0,0,0,0],"pos":0,"len":3,"exploring":true}},{"Schedule":{"preemptions":3,"initial_active":2,"threads":["Pending","Pending","Active","Disabled","Disabled"],"prev":{"index":33,"_p":null},"exploring":true}},{"Schedule":{"preemptions":3,"initial_active":2,"threads":["Pending","Pending","Active","Disabled","Disabled"],"prev":{"index":35,"_p":null},"exploring":true}},{"Schedule":{"preemptions":3,"initial_active":2,"threads":["Pending","Pending","Active","Disabled","Disabled"],"prev":{"index":36,"_p":null},"exploring":true}},{"Schedule":{"preemptions":3,"initial_active":2,"threads":["Pending","Pending","Active","Disabled","Disabled"],"prev":{"index":37,"_p":null},"exploring":true}},{"Schedule":{"preemptions":3,"initial_active":2,"threads":["Pending","Pending","Active","Disabled","Disabled"],"prev":{"index":38,"_p":null},"exploring":true}},{"Schedule":{"preemptions":3,"initial_active":2,"threads":["Pending","Skip","Active","Disabled","Disabled"],"prev":{"index":39,"_p":null},"exploring":true}},{"Schedule":{"preemptions":3,"initial_active":null,"threads":["Visited","Active","Disabled","Disabled","Disabled"],"prev":{"index":40,"_p":null},"exploring":true}}]},"exploring":true,"skipping":false,"exploring_on_start":true}

rtic-sync/src/channel.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,12 @@ impl<T, const N: usize> Sender<'_, T, N> {
323323
});
324324

325325
let idx = poll_fn(|cx| {
326-
if self.is_closed() {
327-
return Poll::Ready(Err(()));
328-
}
329-
330326
// Do all this in one critical section, else there can be race conditions
331-
let queue_idx = critical_section::with(|cs| {
327+
critical_section::with(|cs| {
328+
if self.is_closed() {
329+
return Poll::Ready(Err(()));
330+
}
331+
332332
let wq_empty = self.0.wait_queue.is_empty();
333333
let fq_empty = unsafe {
334334
// SAFETY: the closure does not call `freeq`
@@ -341,7 +341,7 @@ impl<T, const N: usize> Sender<'_, T, N> {
341341
let link = unsafe { link_ptr.get() };
342342
if let Some(link) = link {
343343
if !link.is_popped() {
344-
return None;
344+
return Poll::Pending;
345345
} else {
346346
// Fall through to dequeue
347347
}
@@ -357,7 +357,7 @@ impl<T, const N: usize> Sender<'_, T, N> {
357357
// `link_ptr` lives until the end of the stack frame.
358358
unsafe { self.0.wait_queue.push(Pin::new_unchecked(link_ref)) };
359359

360-
return None;
360+
return Poll::Pending;
361361
}
362362
}
363363

@@ -369,15 +369,8 @@ impl<T, const N: usize> Sender<'_, T, N> {
369369
// Get index as the queue is guaranteed not empty and the wait queue is empty
370370
let idx = unsafe { self.0.freeq(cs, |q| q.pop_front_unchecked()) };
371371

372-
Some(idx)
373-
});
374-
375-
if let Some(idx) = queue_idx {
376-
// Return the index
377372
Poll::Ready(Ok(idx))
378-
} else {
379-
Poll::Pending
380-
}
373+
})
381374
})
382375
.await;
383376

@@ -513,6 +506,7 @@ impl<T, const N: usize> Receiver<'_, T, N> {
513506

514507
// If someone is waiting in the WaiterQueue, wake the first one up.
515508
if let Some(wait_head) = self.0.wait_queue.pop() {
509+
assert!(unsafe { !self.0.freeq(cs, |q| q.is_empty()) });
516510
wait_head.wake();
517511
}
518512

@@ -625,23 +619,29 @@ mod loom_tests {
625619

626620
loom::model(|| {
627621
let (mut spam_tx_send, mut spam_tx_recv) = make_loom_channel!([u8; 20], 1);
622+
let mut cloned = spam_tx_send.clone();
628623

629624
spam_tx_send.try_send([1; 20]).unwrap();
630625

631-
let handle = thread::spawn(move || {
632-
spam_tx_send.try_send([1; 20]).ok();
633-
626+
let handle1 = thread::spawn(move || {
634627
let future = std::pin::pin!(spam_tx_send.send([1; 20]));
635628
let mut future = Cassette::new(future);
636629
if future.poll_on().is_none() {
637630
future.poll_on();
638631
}
639632
});
640633

634+
let handle2 = thread::spawn(move || {
635+
cloned.try_send([1; 20]).ok();
636+
});
637+
641638
spam_tx_recv.try_recv().ok();
642639
spam_tx_recv.try_recv().ok();
643640

644-
handle.join().unwrap();
641+
drop(spam_tx_recv);
642+
643+
handle1.join().unwrap();
644+
handle2.join().unwrap();
645645
});
646646
}
647647
}

0 commit comments

Comments
 (0)