Fix TuiUI deadlock under multi-threading (#1871)

Co-authored-by: Dominik Maier <domenukk@gmail.com>
This commit is contained in:
w1tcher 2024-02-20 00:20:08 +08:00 committed by GitHub
parent ef16e645b7
commit f48e281be8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -579,33 +579,27 @@ impl TuiUI {
) where ) where
B: Backend, B: Backend,
{ {
let items = vec![ let items = {
Row::new(vec![ let app = app.read().unwrap();
Cell::from(Span::raw("clients")), vec![
Cell::from(Span::raw(format!("{}", self.clients))), Row::new(vec![
Cell::from(Span::raw("total execs")), Cell::from(Span::raw("clients")),
Cell::from(Span::raw(format!("{}", app.read().unwrap().total_execs))), Cell::from(Span::raw(format!("{}", self.clients))),
Cell::from(Span::raw("map density")), Cell::from(Span::raw("total execs")),
Cell::from(Span::raw(app.read().unwrap().total_map_density.to_string())), Cell::from(Span::raw(format!("{}", app.total_execs))),
]), Cell::from(Span::raw("map density")),
Row::new(vec![ Cell::from(Span::raw(app.total_map_density.to_string())),
Cell::from(Span::raw("solutions")), ]),
Cell::from(Span::raw(format!( Row::new(vec![
"{}", Cell::from(Span::raw("solutions")),
app.read().unwrap().total_solutions Cell::from(Span::raw(format!("{}", app.total_solutions))),
))), Cell::from(Span::raw("cycle done")),
Cell::from(Span::raw("cycle done")), Cell::from(Span::raw(format!("{}", app.total_cycles_done))),
Cell::from(Span::raw(format!( Cell::from(Span::raw("corpus count")),
"{}", Cell::from(Span::raw(format!("{}", app.total_corpus_count))),
app.read().unwrap().total_cycles_done ]),
))), ]
Cell::from(Span::raw("corpus count")), };
Cell::from(Span::raw(format!(
"{}",
app.read().unwrap().total_corpus_count
))),
]),
];
let chunks = Layout::default() let chunks = Layout::default()
.constraints([Constraint::Percentage(100)].as_ref()) .constraints([Constraint::Percentage(100)].as_ref())
@ -641,30 +635,29 @@ impl TuiUI {
) where ) where
B: Backend, B: Backend,
{ {
let items = vec![ let items = {
Row::new(vec![ let app = app.read().unwrap();
Cell::from(Span::raw("cycles done")), vec![
Cell::from(Span::raw(format!( Row::new(vec![
"{}", Cell::from(Span::raw("cycles done")),
app.read() Cell::from(Span::raw(format!(
.unwrap() "{}",
.clients app.clients
.get(&self.clients_idx) .get(&self.clients_idx)
.map_or(0, |x| x.cycles_done) .map_or(0, |x| x.cycles_done)
))), ))),
]), ]),
Row::new(vec![ Row::new(vec![
Cell::from(Span::raw("solutions")), Cell::from(Span::raw("solutions")),
Cell::from(Span::raw(format!( Cell::from(Span::raw(format!(
"{}", "{}",
app.read() app.clients
.unwrap() .get(&self.clients_idx)
.clients .map_or(0, |x| x.objectives)
.get(&self.clients_idx) ))),
.map_or(0, |x| x.objectives) ]),
))), ]
]), };
];
let chunks = Layout::default() let chunks = Layout::default()
.constraints([Constraint::Percentage(100)].as_ref()) .constraints([Constraint::Percentage(100)].as_ref())
@ -693,40 +686,35 @@ impl TuiUI {
) where ) where
B: Backend, B: Backend,
{ {
let items = vec![ let items = {
Row::new(vec![ let app = app.read().unwrap();
Cell::from(Span::raw("corpus count")), vec![
Cell::from(Span::raw(format!( Row::new(vec![
"{}", Cell::from(Span::raw("corpus count")),
app.read() Cell::from(Span::raw(format!(
.unwrap() "{}",
.clients app.clients.get(&self.clients_idx).map_or(0, |x| x.corpus)
.get(&self.clients_idx) ))),
.map_or(0, |x| x.corpus) ]),
))), Row::new(vec![
]), Cell::from(Span::raw("total execs")),
Row::new(vec![ Cell::from(Span::raw(format!(
Cell::from(Span::raw("total execs")), "{}",
Cell::from(Span::raw(format!( app.clients
"{}", .get(&self.clients_idx)
app.read() .map_or(0, |x| x.executions)
.unwrap() ))),
.clients ]),
.get(&self.clients_idx) Row::new(vec![
.map_or(0, |x| x.executions) Cell::from(Span::raw("map density")),
))), Cell::from(Span::raw(
]), app.clients
Row::new(vec![ .get(&self.clients_idx)
Cell::from(Span::raw("map density")), .map_or("0%".to_string(), |x| x.map_density.to_string()),
Cell::from(Span::raw( )),
app.read() ]),
.unwrap() ]
.clients };
.get(&self.clients_idx)
.map_or("0%".to_string(), |x| x.map_density.to_string()),
)),
]),
];
let chunks = Layout::default() let chunks = Layout::default()
.constraints([Constraint::Percentage(100)].as_ref()) .constraints([Constraint::Percentage(100)].as_ref())