Files
drop-app/src-tauri/download_manager/src/util/download_thread_control_flag.rs
quexeky 0147956b5f chore: Most refactoring except appstate, backuperror, and main workspace
Still needs a massive go-over because there shouldn't be anything referencing tauri in any of the workspaces except the original one

Signed-off-by: quexeky <git@quexeky.dev>
2025-10-09 07:46:17 +11:00

47 lines
1.1 KiB
Rust

use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub enum DownloadThreadControlFlag {
Stop,
Go,
}
/// Go => true
/// Stop => false
impl From<DownloadThreadControlFlag> for bool {
fn from(value: DownloadThreadControlFlag) -> Self {
match value {
DownloadThreadControlFlag::Go => true,
DownloadThreadControlFlag::Stop => false,
}
}
}
/// true => Go
/// false => Stop
impl From<bool> for DownloadThreadControlFlag {
fn from(value: bool) -> Self {
if value { DownloadThreadControlFlag::Go } else { DownloadThreadControlFlag::Stop }
}
}
#[derive(Clone)]
pub struct DownloadThreadControl {
inner: Arc<AtomicBool>,
}
impl DownloadThreadControl {
pub fn new(flag: DownloadThreadControlFlag) -> Self {
Self {
inner: Arc::new(AtomicBool::new(flag.into())),
}
}
pub fn get(&self) -> DownloadThreadControlFlag {
self.inner.load(Ordering::Acquire).into()
}
pub fn set(&self, flag: DownloadThreadControlFlag) {
self.inner.store(flag.into(), Ordering::Release);
}
}