Skip to content

Commit 2ec4015

Browse files
committed
add missing files
1 parent f5e7901 commit 2ec4015

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/hive/inner/queue/closed.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::atomic::{Atomic, AtomicU8};
2+
3+
const OPEN: u8 = 0;
4+
const CLOSED_PUSH: u8 = 1;
5+
const CLOSED_POP: u8 = 2;
6+
7+
pub struct Closed(AtomicU8);
8+
9+
impl Closed {
10+
pub fn is_closed(&self) -> bool {
11+
self.0.get() > OPEN
12+
}
13+
14+
pub fn can_push(&self) -> bool {
15+
self.0.get() < CLOSED_PUSH
16+
}
17+
18+
pub fn can_pop(&self) -> bool {
19+
self.0.get() < CLOSED_POP
20+
}
21+
22+
pub fn set(&self, urgent: bool) {
23+
self.0.set(if urgent { CLOSED_POP } else { CLOSED_PUSH });
24+
}
25+
}
26+
27+
impl Default for Closed {
28+
fn default() -> Self {
29+
Self(AtomicU8::new(OPEN))
30+
}
31+
}

0 commit comments

Comments
 (0)