Skip to content

Commit c6ba6fe

Browse files
committed
rtic-sync: improve safety comments
1 parent 3d7fa3d commit c6ba6fe

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

rtic-sync/src/channel.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl SlotPtr {
216216
/// Replace the value of this slot with `new_value`, and return
217217
/// the old value.
218218
///
219-
/// SAFETY: the pointer in this `SlotPtr` must still be valid.
219+
/// SAFETY: the pointer in this `SlotPtr` must be valid for writes.
220220
unsafe fn replace(
221221
&mut self,
222222
new_value: Option<u8>,
@@ -317,7 +317,7 @@ impl<T, const N: usize> Sender<'_, T, N> {
317317
// is no way for anything else to access the free slot ptr. Gotta think
318318
// about this a bit more...
319319
//
320-
// SAFETY(replace): the data pointed to by `free_slot_ptr2` is still alive.
320+
// SAFETY(replace): `free_slot_ptr2` is valid for writes.
321321
critical_section::with(|cs| {
322322
if let Some(freed_slot) = unsafe { free_slot_ptr2.replace(None, cs) } {
323323
debug_assert!(!self.0.access(cs).freeq.is_full());
@@ -362,9 +362,8 @@ impl<T, const N: usize> Sender<'_, T, N> {
362362
}
363363
}
364364

365-
// SAFETY: the value pointed to by `free_slot_ptr` is still alive.
366-
let slot = unsafe { free_slot_ptr.replace(None, cs) }
367-
.or_else(|| self.0.access(cs).freeq.pop_back());
365+
// SAFETY: `free_slot_ptr` is valid for writes, as `free_slot_ptr` is still alive.
366+
let slot = unsafe { free_slot_ptr.replace(None, cs) };
368367

369368
if let Some(slot) = slot {
370369
Poll::Ready(Ok(slot))
@@ -475,7 +474,7 @@ impl<T, const N: usize> Receiver<'_, T, N> {
475474

476475
// If someone is waiting in the WaiterQueue, wake the first one up & hand it the free slot.
477476
if let Some((wait_head, mut freeq_slot)) = self.0.wait_queue.pop() {
478-
// SAFETY: the value pointed to by `freeq_slot` is still alive: we are in a critical
477+
// SAFETY: `freeq_slot` is valid for writes: we are in a critical
479478
// section & the `SlotPtr` lives for at least the duration of the wait queue link.
480479
unsafe { freeq_slot.replace(Some(rs), cs) };
481480
wait_head.wake();

0 commit comments

Comments
 (0)