beekeeper/hive/inner/queue/
status.rs1use crate::atomic::{Atomic, AtomicU8};
2
3const OPEN: u8 = 0;
4const CLOSED_PUSH: u8 = 1;
5const CLOSED_POP: u8 = 2;
6
7pub struct Status(AtomicU8);
13
14impl Status {
15    pub fn is_closed(&self) -> bool {
17        self.0.get() > OPEN
18    }
19
20    pub fn can_push(&self) -> bool {
22        self.0.get() < CLOSED_PUSH
23    }
24
25    pub fn can_pop(&self) -> bool {
27        self.0.get() < CLOSED_POP
28    }
29
30    pub fn set(&self, urgent: bool) {
33        let new_status = if urgent { CLOSED_POP } else { CLOSED_PUSH };
35        if new_status > self.0.get() {
36            self.0.set(new_status);
37        }
38    }
39}
40
41impl Default for Status {
42    fn default() -> Self {
43        Self(AtomicU8::new(OPEN))
44    }
45}