2021-05-18 03:11:19 +00:00
|
|
|
// Copyright (c) 2021 Weird Constructor <weirdconstructor@gmail.com>
|
2021-08-04 01:58:43 +00:00
|
|
|
// This file is a part of HexoDSP. Released under GPL-3.0-or-later.
|
2021-05-18 03:11:19 +00:00
|
|
|
// See README.md and COPYING for details.
|
|
|
|
|
|
|
|
use super::DropMsg;
|
|
|
|
|
|
|
|
use ringbuf::Consumer;
|
|
|
|
|
|
|
|
/// For receiving deleted/overwritten nodes from the backend
|
|
|
|
/// thread and dropping them.
|
|
|
|
pub(crate) struct DropThread {
|
|
|
|
terminate: std::sync::Arc<std::sync::atomic::AtomicBool>,
|
|
|
|
th: Option<std::thread::JoinHandle<()>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DropThread {
|
|
|
|
pub(crate) fn new(mut graph_drop_con: Consumer<DropMsg>) -> Self {
|
|
|
|
let terminate =
|
|
|
|
std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
|
|
|
|
let th_terminate = terminate.clone();
|
|
|
|
|
|
|
|
let th = std::thread::spawn(move || {
|
|
|
|
loop {
|
|
|
|
if th_terminate.load(std::sync::atomic::Ordering::Relaxed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while let Some(_node) = graph_drop_con.pop() {
|
|
|
|
// drop it ...
|
2021-07-23 01:51:43 +00:00
|
|
|
//d// println!("Dropped some shit...");
|
2021-05-18 03:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(250));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self {
|
|
|
|
th: Some(th),
|
|
|
|
terminate,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for DropThread {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
self.terminate.store(true, std::sync::atomic::Ordering::Relaxed);
|
|
|
|
let _ = self.th.take().unwrap().join();
|
|
|
|
}
|
|
|
|
}
|