mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-04 01:55:41 +00:00
dirty: fix Default, remove unused DirtyState
This commit is contained in:
@@ -1,20 +1,9 @@
|
|||||||
use derivative::Derivative;
|
use derive_more::Deref;
|
||||||
use derive_more::{Deref, DerefMut};
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use tokio::sync::Notify;
|
use tokio::sync::Notify;
|
||||||
|
|
||||||
#[derive(Debug, Default, Deref, DerefMut)]
|
#[derive(Debug, Deref)]
|
||||||
pub struct DirtyState<T> {
|
|
||||||
#[deref]
|
|
||||||
#[deref_mut]
|
|
||||||
flags: T,
|
|
||||||
pub notify: Notify,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Derivative, Debug, Deref)]
|
|
||||||
#[derivative(Default)]
|
|
||||||
pub struct DirtyFlag {
|
pub struct DirtyFlag {
|
||||||
#[derivative(Default(value = "AtomicBool::new(true)"))]
|
|
||||||
dirty: AtomicBool,
|
dirty: AtomicBool,
|
||||||
#[deref]
|
#[deref]
|
||||||
notify: Notify,
|
notify: Notify,
|
||||||
@@ -22,9 +11,15 @@ pub struct DirtyFlag {
|
|||||||
|
|
||||||
impl DirtyFlag {
|
impl DirtyFlag {
|
||||||
pub fn new(value: bool) -> Self {
|
pub fn new(value: bool) -> Self {
|
||||||
|
let notify = Notify::new();
|
||||||
|
|
||||||
|
if value {
|
||||||
|
notify.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
dirty: AtomicBool::new(value),
|
dirty: AtomicBool::new(value),
|
||||||
notify: Notify::new(),
|
notify,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,3 +36,9 @@ impl DirtyFlag {
|
|||||||
self.dirty.swap(false, Ordering::Acquire)
|
self.dirty.swap(false, Ordering::Acquire)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for DirtyFlag {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user