mirror of
https://github.com/uutils/coreutils
synced 2024-12-26 21:13:26 +00:00
dd: Simplify loop of progress Alarm thread
This commit is contained in:
parent
cf7b90bbe7
commit
52c93a4d10
1 changed files with 5 additions and 7 deletions
|
@ -80,20 +80,18 @@ pub struct Alarm {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Alarm {
|
impl Alarm {
|
||||||
pub fn with_interval(interval: Duration) -> Alarm {
|
pub fn with_interval(interval: Duration) -> Self {
|
||||||
let trigger = Arc::new(AtomicBool::default());
|
let trigger = Arc::new(AtomicBool::default());
|
||||||
|
|
||||||
let weak_trigger = Arc::downgrade(&trigger);
|
let weak_trigger = Arc::downgrade(&trigger);
|
||||||
std::thread::spawn(move || loop {
|
std::thread::spawn(move || {
|
||||||
sleep(interval);
|
while let Some(trigger) = weak_trigger.upgrade() {
|
||||||
if let Some(trigger) = weak_trigger.upgrade() {
|
sleep(interval);
|
||||||
trigger.store(true, Relaxed);
|
trigger.store(true, Relaxed);
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Alarm { interval, trigger }
|
Self { interval, trigger }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_triggered(&self) -> bool {
|
pub fn is_triggered(&self) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue