Skip to content

Commit

Permalink
fix race condition on relinquish focus v result return for dynamic an…
Browse files Browse the repository at this point in the history
…d progress modals

There's a race condition between the return of a blocking scalar
and when focus is relinquished.

This causes chained graphics operations to get dropped sometimes.

Move the return result to after the focus switch; this allows us
to elimate some dead waits.
  • Loading branch information
bunnie committed Nov 6, 2022
1 parent 5a0e3e5 commit b0f443b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
7 changes: 5 additions & 2 deletions services/modals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,15 @@ impl Modals {
Ok(())
}

/// close the progress bar, regardless of the current state
/// Close the progress bar, regardless of the current state
/// This is a blocking call, because you want the GAM to revert focus back to your context before you
/// continue with any drawing operations. Otherwise, they could be missed as the modal is still covering
/// your window.
pub fn finish_progress(&self) -> Result<(), xous::Error> {
self.lock();
send_message(
self.conn,
Message::new_scalar(
Message::new_blocking_scalar(
Opcode::StopProgress.to_usize().unwrap(),
self.token[0] as usize,
self.token[1] as usize,
Expand Down
18 changes: 10 additions & 8 deletions services/modals/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,15 @@ fn wrapped_main() -> ! {
)
.expect("couldn't initiate UX op");
}
Some(Opcode::StopProgress) => msg_scalar_unpack!(msg, t0, t1, t2, t3, {
Some(Opcode::StopProgress) => msg_blocking_scalar_unpack!(msg, t0, t1, t2, t3, {
let token = [t0 as u32, t1 as u32, t2 as u32, t3 as u32];
if token != token_lock.unwrap_or(default_nonce) {
log::warn!("Attempt to access modals without a mutex lock. Ignoring.");
continue;
}
send_message(
renderer_cid,
Message::new_scalar(Opcode::FinishProgress.to_usize().unwrap(), 0, 0, 0, 0),
Message::new_scalar(Opcode::FinishProgress.to_usize().unwrap(), msg.sender as usize, 0, 0, 0),
)
.expect("couldn't update progress bar");
}),
Expand Down Expand Up @@ -401,10 +401,6 @@ fn wrapped_main() -> ! {
log::warn!("Attempt to access modals without a mutex lock. Ignoring.");
continue;
}
if let Some(sender) = dynamic_notification_listener.take() {
// unblock the listener with no key hit response
xous::return_scalar2(sender, 0, 0,).unwrap();
}
send_message(
renderer_cid,
Message::new_scalar(
Expand Down Expand Up @@ -700,9 +696,11 @@ fn wrapped_main() -> ! {
}
}
}
Some(Opcode::FinishProgress) => {
Some(Opcode::FinishProgress) => msg_scalar_unpack!(msg, caller, _, _, _, {
renderer_modal.gam.relinquish_focus().unwrap();
op = RendererState::None;
// unblock the caller, which was forwarded on as the first argument
xous::return_scalar(caller as Sender, 0).ok();
token_lock = next_lock(&mut work_queue);
/*
if work_queue.len() > 0 {
Expand All @@ -712,7 +710,7 @@ fn wrapped_main() -> ! {
} else {
token_lock = None;
}*/
}
}),
Some(Opcode::DoUpdateDynamicNotification) => match op {
RendererState::RunDynamicNotification(config) => {
//log::set_max_level(log::LevelFilter::Trace);
Expand Down Expand Up @@ -747,6 +745,10 @@ fn wrapped_main() -> ! {
Some(Opcode::DoCloseDynamicNotification) => {
renderer_modal.gam.relinquish_focus().unwrap();
op = RendererState::None;
if let Some(sender) = dynamic_notification_listener.take() {
// unblock the listener with no key hit response
xous::return_scalar2(sender, 0, 0,).unwrap();
}
token_lock = next_lock(&mut work_queue);
},
Some(Opcode::HandleDynamicNotificationKeyhit) => msg_scalar_unpack!(msg, k, _, _, _, {
Expand Down
1 change: 0 additions & 1 deletion services/shellchat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ fn wrapped_main() -> ! {
}
}
}
tt.sleep_ms(100).ok(); // this allows the shellchat context to foreground before calling the redraw
xous::send_message(main_conn,
xous::Message::new_scalar(ShellOpcode::Redraw.to_usize().unwrap(), 0, 0, 0, 0)
).ok();
Expand Down

0 comments on commit b0f443b

Please sign in to comment.