mirror of
https://github.com/uutils/coreutils
synced 2024-12-26 04:53:25 +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 {
|
||||
pub fn with_interval(interval: Duration) -> Alarm {
|
||||
pub fn with_interval(interval: Duration) -> Self {
|
||||
let trigger = Arc::new(AtomicBool::default());
|
||||
|
||||
let weak_trigger = Arc::downgrade(&trigger);
|
||||
std::thread::spawn(move || loop {
|
||||
sleep(interval);
|
||||
if let Some(trigger) = weak_trigger.upgrade() {
|
||||
std::thread::spawn(move || {
|
||||
while let Some(trigger) = weak_trigger.upgrade() {
|
||||
sleep(interval);
|
||||
trigger.store(true, Relaxed);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
Alarm { interval, trigger }
|
||||
Self { interval, trigger }
|
||||
}
|
||||
|
||||
pub fn is_triggered(&self) -> bool {
|
||||
|
|
Loading…
Reference in a new issue