pop front for queue?
This commit is contained in:
parent
26b6ef264c
commit
fad57b74e9
|
@ -90,6 +90,22 @@ impl<T> Slot<T> {
|
|||
})
|
||||
}
|
||||
|
||||
/// this operation isn't atomic.
|
||||
unsafe fn pop_front(&self) -> Option<T> {
|
||||
// SAFETY: The caller must ensure that they have exclusive access to the slot
|
||||
if self.is_set() {
|
||||
let next = self.next_ptr();
|
||||
unsafe { (next.as_ref()).pop_front() }
|
||||
} else {
|
||||
// SAFETY: The value is only initialized when the state is set to 1.
|
||||
if self.next_and_state.tag(Ordering::Acquire) == 1 {
|
||||
Some(unsafe { self.value.as_ref_unchecked().assume_init_read() })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// the caller must ensure that they have exclusive access to the slot
|
||||
unsafe fn push(&self, value: T) {
|
||||
if self.is_set() {
|
||||
|
|
Loading…
Reference in a new issue