Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/actor/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::cell::RefCell;
use std::fmt::Debug;
use std::num::NonZeroU32;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, LazyLock, Mutex};
use std::thread;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -301,6 +302,8 @@ pub struct AppThreadHandle {
requests_tx: actor::Sender<Request>,
interactive_frames: InteractiveFrameQueue,
frame_authority: FrameAuthority,
/// Set once the actor has attached to its app, shared by every clone.
attached: Arc<AtomicBool>,
}

/// The topology accepted when this producer was created. Clones held by an old
Expand Down Expand Up @@ -461,6 +464,7 @@ impl AppThreadHandle {
requests_tx,
interactive_frames: Default::default(),
frame_authority: Default::default(),
attached: Default::default(),
}
}

Expand All @@ -471,6 +475,7 @@ impl AppThreadHandle {
requests_tx,
interactive_frames: Default::default(),
frame_authority: Default::default(),
attached: Default::default(),
},
rx,
)
Expand All @@ -482,6 +487,11 @@ impl AppThreadHandle {
self.requests_tx.same_channel(&other.requests_tx)
}

/// Whether the actor got through `init`: watching its app and holding its windows.
pub(crate) fn is_attached(&self) -> bool { self.attached.load(Ordering::Relaxed) }

pub(crate) fn mark_attached(&self) { self.attached.store(true, Ordering::Relaxed) }

pub(crate) fn set_topology_authority(
&mut self,
guard: &crate::actor::spaces::TopologyGuard,
Expand Down Expand Up @@ -1092,6 +1102,7 @@ impl State {
if !self.init(handle.clone(), info) {
return;
}
handle.mark_attached();

let this = RefCell::new(self);
// The raises channel is owned by State, so joining both tasks would keep
Expand Down
10 changes: 9 additions & 1 deletion src/actor/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ impl ProcessActor {

let pid = match unsafe { pid_for_psn(&psn) } {
Some(pid) => pid,
None => return NO_ERR,
None => {
// A terminated process's PSN no longer resolves to a pid by
// the time the event arrives; look for the apps that ended.
if ev.kind == K_EVENT_APP_TERMINATED {
debug!("Carbon: App terminated (pid unknown)");
wm_sender.send(WmEvent::AppsMayHaveTerminated);
}
return NO_ERR;
}
};

match ev.kind {
Expand Down
Loading