Skip to content

Commit

Permalink
safety: ensure RMain exists before checking busy state
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcphers committed Nov 1, 2023
1 parent c54bf86 commit 8c1baab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 11 additions & 1 deletion crates/ark/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ pub struct RMain {

dap: Arc<Mutex<Dap>>,
is_debugging: bool,

/// Whether or not R itself is actively busy.
/// This does not represent the busy state of the kernel.
pub is_busy: bool,
Expand Down Expand Up @@ -408,6 +408,16 @@ impl RMain {
RMain::get_mut()
}

/// Indicate whether RMain has been created and is initialized.
pub fn initialized() -> bool {
unsafe {
match &R_MAIN {
Some(main) => !main.initializing,
None => false,
}
}
}

/// Access a mutable reference to the singleton instance of this struct
///
/// SAFETY: Accesses must occur after `start_r()` initializes it, and must
Expand Down
9 changes: 6 additions & 3 deletions crates/ark/src/kernel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// kernel.rs
//
// Copyright (C) 2022 Posit Software, PBC. All rights reserved.
// Copyright (C) 2023 Posit Software, PBC. All rights reserved.
//
//

Expand Down Expand Up @@ -73,8 +73,11 @@ impl Kernel {

// Get the current busy status
let busy = r_task(|| {
let main = RMain::get();
main.is_busy
if RMain::initialized() {
RMain::get().is_busy
} else {
false
}
});
self.send_event(PositronEvent::Busy(BusyEvent { busy }));
}
Expand Down

0 comments on commit 8c1baab

Please sign in to comment.