Skip to content

Commit d0f6046

Browse files
committed
rtic-sync: improve comments
1 parent 2111d6f commit d0f6046

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

rtic-sync/src/channel.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,12 @@ impl<T, const N: usize> Sender<'_, T, N> {
342342
// We are already in the wait queue.
343343
if let Some(link) = link {
344344
if link.is_popped() {
345+
// SAFETY: `free_slot_ptr` is valid for writes until the end of this future.
346+
let slot = unsafe { free_slot_ptr.replace(None, cs) };
347+
345348
// If our link is popped, then:
346349
// 1. We were popped by `try_recv` and it provided us with a slot.
347350
// 2. We were popped by `Receiver::drop` and it did not provide us with a slot, and the channel is closed.
348-
let slot = unsafe { free_slot_ptr.replace(None, cs) };
349-
350351
if let Some(slot) = slot {
351352
Poll::Ready(Ok(slot))
352353
} else {
@@ -365,10 +366,10 @@ impl<T, const N: usize> Sender<'_, T, N> {
365366

366367
// SAFETY(new_unchecked): The address to the link is stable as it is defined
367368
// outside this stack frame.
368-
// SAFETY(push): `link_ref` lifetime comes from `link_ptr` that is shadowed,
369-
// and we make sure in `dropper` that the link is removed from the queue
369+
// SAFETY(push): `link_ref` lifetime comes from `link_ptr` and `free_slot_ptr` that
370+
// are shadowed and we make sure in `dropper` that the link is removed from the queue
370371
// before dropping `link_ptr` AND `dropper` makes sure that the shadowed
371-
// `link_ptr` lives until the end of the stack frame.
372+
// `ptr`s live until the end of the stack frame.
372373
unsafe { self.0.wait_queue.push(Pin::new_unchecked(link_ref)) };
373374

374375
Poll::Pending

0 commit comments

Comments
 (0)