mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-01 08:49:16 +00:00
node & server: separate dirty flag, remove DirtyState
This commit is contained in:
@@ -11,24 +11,33 @@ pub struct DirtyState<T> {
|
||||
pub notify: Notify,
|
||||
}
|
||||
|
||||
#[derive(Derivative, Debug)]
|
||||
#[derive(Derivative, Debug, Deref)]
|
||||
#[derivative(Default)]
|
||||
pub struct DirtyFlag(#[derivative(Default(value = "AtomicBool::new(true)"))] AtomicBool);
|
||||
pub struct DirtyFlag {
|
||||
#[derivative(Default(value = "AtomicBool::new(true)"))]
|
||||
dirty: AtomicBool,
|
||||
#[deref]
|
||||
notify: Notify,
|
||||
}
|
||||
|
||||
impl DirtyFlag {
|
||||
pub fn new(value: bool) -> Self {
|
||||
Self(AtomicBool::new(value))
|
||||
Self {
|
||||
dirty: AtomicBool::new(value),
|
||||
notify: Notify::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark(&self) {
|
||||
self.0.store(true, Ordering::Release);
|
||||
self.dirty.store(true, Ordering::Release);
|
||||
self.notify.notify_one();
|
||||
}
|
||||
|
||||
pub fn peek(&self) -> bool {
|
||||
self.0.load(Ordering::Acquire)
|
||||
self.dirty.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
pub fn reset(&self) -> bool {
|
||||
self.0.swap(false, Ordering::Acquire)
|
||||
self.dirty.swap(false, Ordering::Acquire)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user