From fdc40f52d977043d5075347db911520b032b89da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Mon, 22 Mar 2021 12:37:03 +0100 Subject: [PATCH 1/2] give more threads a fixed name --- server-cli/src/tui_runner.rs | 190 ++++++++++++++++++----------------- voxygen/anim/src/dyn_lib.rs | 2 +- 2 files changed, 99 insertions(+), 93 deletions(-) diff --git a/server-cli/src/tui_runner.rs b/server-cli/src/tui_runner.rs index e215496bb8..2ad1cfa457 100644 --- a/server-cli/src/tui_runner.rs +++ b/server-cli/src/tui_runner.rs @@ -56,104 +56,16 @@ impl Tui { } 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 running2 = Arc::clone(&running); + let builder = std::thread::Builder::new().name("tui_runner".to_owned()); let background = if basic { - std::thread::spawn(move || { - while running2.load(Ordering::Relaxed) { - let mut line = String::new(); - - match io::stdin().read_line(&mut line) { - Err(e) => { - error!( - ?e, - "couldn't read from stdin, cli commands are disabled now!" - ); - break; - }, - Ok(0) => { - //Docker seem to send EOF all the time - warn!("EOF received, cli commands are disabled now!"); - break; - }, - Ok(_) => { - debug!(?line, "basic mode: command entered"); - crate::cmd::parse_command(&line, &mut msg_s); - }, - } - } - }); - + builder.spawn(|| Self::work_b(running2, msg_s)).unwrap(); None } else { - Some(std::thread::spawn(move || { - // Start the tui - let mut stdout = io::stdout(); - execute!(stdout, EnterAlternateScreen, EnableMouseCapture).unwrap(); - - enable_raw_mode().unwrap(); - - let backend = CrosstermBackend::new(stdout); - let mut terminal = Terminal::new(backend).unwrap(); - - let mut input = String::new(); - - if let Err(e) = terminal.clear() { - error!(?e, "couldn't clean terminal"); - }; - - while running2.load(Ordering::Relaxed) { - if let Err(e) = terminal.draw(|f| { - let (log_rect, input_rect) = if f.size().height > 6 { - let mut log_rect = f.size(); - log_rect.height -= 3; - - let mut input_rect = f.size(); - input_rect.y = input_rect.height - 3; - input_rect.height = 3; - - (log_rect, input_rect) - } else { - (f.size(), Rect::default()) - }; - - let block = Block::default().borders(Borders::ALL); - - let wrap = Wrap { - scroll_callback: Some(Box::new(|text_area, lines| { - LOG.resize(text_area.height as usize); - let len = lines.len() as u16; - (len.saturating_sub(text_area.height), 0) - })), - ..Default::default() - }; - - let logger = Paragraph::new(LOG.inner.lock().unwrap().clone()) - .block(block) - .wrap(wrap); - f.render_widget(logger, log_rect); - - let text: Text = input.as_str().into(); - - let block = Block::default().borders(Borders::ALL); - let size = block.inner(input_rect); - - let x = (size.x + text.width() as u16).min(size.width); - - let input_field = Paragraph::new(text).block(block); - f.render_widget(input_field, input_rect); - - f.set_cursor(x, size.y); - }) { - warn!(?e, "couldn't draw frame"); - }; - if crossterm::event::poll(Duration::from_millis(100)).unwrap() { - Self::handle_events(&mut input, &mut msg_s); - }; - } - })) + Some(builder.spawn(|| Self::work_e(running2, msg_s)).unwrap()) }; Self { @@ -164,6 +76,100 @@ impl Tui { } } + /// In a seperate Thread + fn work_b(running: Arc, mut msg_s: mpsc::Sender) { + while running.load(Ordering::Relaxed) { + let mut line = String::new(); + + match io::stdin().read_line(&mut line) { + Err(e) => { + error!( + ?e, + "couldn't read from stdin, cli commands are disabled now!" + ); + break; + }, + Ok(0) => { + //Docker seem to send EOF all the time + warn!("EOF received, cli commands are disabled now!"); + break; + }, + Ok(_) => { + debug!(?line, "basic mode: command entered"); + crate::cmd::parse_command(&line, &mut msg_s); + }, + } + } + } + + /// In a seperate Thread + fn work_e(running: Arc, mut msg_s: mpsc::Sender) { + // Start the tui + let mut stdout = io::stdout(); + execute!(stdout, EnterAlternateScreen, EnableMouseCapture).unwrap(); + + enable_raw_mode().unwrap(); + + let backend = CrosstermBackend::new(stdout); + let mut terminal = Terminal::new(backend).unwrap(); + + let mut input = String::new(); + + if let Err(e) = terminal.clear() { + error!(?e, "couldn't clean terminal"); + }; + + while running.load(Ordering::Relaxed) { + if let Err(e) = terminal.draw(|f| { + let (log_rect, input_rect) = if f.size().height > 6 { + let mut log_rect = f.size(); + log_rect.height -= 3; + + let mut input_rect = f.size(); + input_rect.y = input_rect.height - 3; + input_rect.height = 3; + + (log_rect, input_rect) + } else { + (f.size(), Rect::default()) + }; + + let block = Block::default().borders(Borders::ALL); + + let wrap = Wrap { + scroll_callback: Some(Box::new(|text_area, lines| { + LOG.resize(text_area.height as usize); + let len = lines.len() as u16; + (len.saturating_sub(text_area.height), 0) + })), + ..Default::default() + }; + + let logger = Paragraph::new(LOG.inner.lock().unwrap().clone()) + .block(block) + .wrap(wrap); + f.render_widget(logger, log_rect); + + let text: Text = input.as_str().into(); + + let block = Block::default().borders(Borders::ALL); + let size = block.inner(input_rect); + + let x = (size.x + text.width() as u16).min(size.width); + + let input_field = Paragraph::new(text).block(block); + f.render_widget(input_field, input_rect); + + f.set_cursor(x, size.y); + }) { + warn!(?e, "couldn't draw frame"); + }; + if crossterm::event::poll(Duration::from_millis(100)).unwrap() { + Self::handle_events(&mut input, &mut msg_s); + }; + } + } + pub fn shutdown(basic: bool) { if !basic { let mut stdout = io::stdout(); diff --git a/voxygen/anim/src/dyn_lib.rs b/voxygen/anim/src/dyn_lib.rs index 4c39922032..8c7feaf030 100644 --- a/voxygen/anim/src/dyn_lib.rs +++ b/voxygen/anim/src/dyn_lib.rs @@ -146,7 +146,7 @@ pub fn init() { // Start reloader that watcher signals // "Debounces" events since I can't find the option to do this in the latest // `notify` - thread::spawn(move || { + std::thread::Builder::new("voxygen_anim_watcher".to_owned()).spawn(move || { let mut modified_paths = std::collections::HashSet::new(); while let Ok(path) = reload_recv.recv() { modified_paths.insert(path); From 667faca5a5e46bf89210de39085396803f8b738a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Mon, 22 Mar 2021 12:37:38 +0100 Subject: [PATCH 2/2] update asset_manager --- Cargo.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0aa5b44ff6..0e7da1c04d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,9 +45,9 @@ checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" [[package]] name = "ahash" -version = "0.6.3" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "796540673305a66d127804eef19ad696f1f204b8c1025aaca4958c17eab32877" +checksum = "7f200cbb1e856866d9eade941cf3aa0c5d7dd36f74311c4273b494f4ef036957" dependencies = [ "getrandom 0.2.2", "once_cell", @@ -215,11 +215,11 @@ dependencies = [ [[package]] name = "assets_manager" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac94eeee6ebd1165959e440836a452109f9f839d6cfde12974d75a5b4222406" +checksum = "792c2eca2af86c76ffd3e72ca564c33b5a5551d5ac3f4f87dce8c0b7c6434061" dependencies = [ - "ahash 0.6.3", + "ahash 0.7.2", "bincode", "crossbeam-channel", "log",