use crate::atomic::{Atomic, AtomicU8};
const OPEN: u8 = 0;
const CLOSED_PUSH: u8 = 1;
const CLOSED_POP: u8 = 2;
pub struct Status(AtomicU8);
impl Status {
pub fn is_closed(&self) -> bool {
self.0.get() > OPEN
}
pub fn can_push(&self) -> bool {
self.0.get() < CLOSED_PUSH
}
pub fn can_pop(&self) -> bool {
self.0.get() < CLOSED_POP
}
pub fn set(&self, urgent: bool) {
let new_status = if urgent { CLOSED_POP } else { CLOSED_PUSH };
if new_status > self.0.get() {
self.0.set(new_status);
}
}
}
impl Default for Status {
fn default() -> Self {
Self(AtomicU8::new(OPEN))
}
}