Merge branch 'xMAC94x/thread_names' into 'master'

xmac94x/thread names

See merge request veloren/veloren!1969
This commit is contained in:
Marcel 2021-03-22 12:56:45 +00:00
commit 09c9615672
3 changed files with 104 additions and 98 deletions

10
Cargo.lock generated
View File

@ -45,9 +45,9 @@ checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.6.3" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "796540673305a66d127804eef19ad696f1f204b8c1025aaca4958c17eab32877" checksum = "7f200cbb1e856866d9eade941cf3aa0c5d7dd36f74311c4273b494f4ef036957"
dependencies = [ dependencies = [
"getrandom 0.2.2", "getrandom 0.2.2",
"once_cell", "once_cell",
@ -215,11 +215,11 @@ dependencies = [
[[package]] [[package]]
name = "assets_manager" name = "assets_manager"
version = "0.4.3" version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dac94eeee6ebd1165959e440836a452109f9f839d6cfde12974d75a5b4222406" checksum = "792c2eca2af86c76ffd3e72ca564c33b5a5551d5ac3f4f87dce8c0b7c6434061"
dependencies = [ dependencies = [
"ahash 0.6.3", "ahash 0.7.2",
"bincode", "bincode",
"crossbeam-channel", "crossbeam-channel",
"log", "log",

View File

@ -56,13 +56,29 @@ impl Tui {
} }
pub fn run(basic: bool) -> Self { pub fn run(basic: bool) -> Self {
let (mut msg_s, msg_r) = mpsc::channel(); let (msg_s, msg_r) = mpsc::channel();
let running = Arc::new(AtomicBool::new(true)); let running = Arc::new(AtomicBool::new(true));
let running2 = Arc::clone(&running); let running2 = Arc::clone(&running);
let builder = std::thread::Builder::new().name("tui_runner".to_owned());
let background = if basic { let background = if basic {
std::thread::spawn(move || { builder.spawn(|| Self::work_b(running2, msg_s)).unwrap();
while running2.load(Ordering::Relaxed) { None
} else {
Some(builder.spawn(|| Self::work_e(running2, msg_s)).unwrap())
};
Self {
msg_r,
background,
basic,
running,
}
}
/// In a seperate Thread
fn work_b(running: Arc<AtomicBool>, mut msg_s: mpsc::Sender<Message>) {
while running.load(Ordering::Relaxed) {
let mut line = String::new(); let mut line = String::new();
match io::stdin().read_line(&mut line) { match io::stdin().read_line(&mut line) {
@ -84,11 +100,10 @@ impl Tui {
}, },
} }
} }
}); }
None /// In a seperate Thread
} else { fn work_e(running: Arc<AtomicBool>, mut msg_s: mpsc::Sender<Message>) {
Some(std::thread::spawn(move || {
// Start the tui // Start the tui
let mut stdout = io::stdout(); let mut stdout = io::stdout();
execute!(stdout, EnterAlternateScreen, EnableMouseCapture).unwrap(); execute!(stdout, EnterAlternateScreen, EnableMouseCapture).unwrap();
@ -104,7 +119,7 @@ impl Tui {
error!(?e, "couldn't clean terminal"); error!(?e, "couldn't clean terminal");
}; };
while running2.load(Ordering::Relaxed) { while running.load(Ordering::Relaxed) {
if let Err(e) = terminal.draw(|f| { if let Err(e) = terminal.draw(|f| {
let (log_rect, input_rect) = if f.size().height > 6 { let (log_rect, input_rect) = if f.size().height > 6 {
let mut log_rect = f.size(); let mut log_rect = f.size();
@ -153,15 +168,6 @@ impl Tui {
Self::handle_events(&mut input, &mut msg_s); Self::handle_events(&mut input, &mut msg_s);
}; };
} }
}))
};
Self {
msg_r,
background,
basic,
running,
}
} }
pub fn shutdown(basic: bool) { pub fn shutdown(basic: bool) {

View File

@ -146,7 +146,7 @@ pub fn init() {
// Start reloader that watcher signals // Start reloader that watcher signals
// "Debounces" events since I can't find the option to do this in the latest // "Debounces" events since I can't find the option to do this in the latest
// `notify` // `notify`
thread::spawn(move || { std::thread::Builder::new("voxygen_anim_watcher".to_owned()).spawn(move || {
let mut modified_paths = std::collections::HashSet::new(); let mut modified_paths = std::collections::HashSet::new();
while let Ok(path) = reload_recv.recv() { while let Ok(path) = reload_recv.recv() {
modified_paths.insert(path); modified_paths.insert(path);