Clean up instance tracking
We used to hold a Weak<CompOsInstance>, so that we could allow clients
to retrieve the current running instance. But we haven't supported
that since commit 616f822f8a4186f9d29edc6a75cf9d31350ecc7d, and it
confuses the ownership semantics.
We still need to track whether an instance is running, but we can do
that via a separate Arc<()> that is kept alive by the instance.
Bug: 236581575
Test: compos_cmd test-compile
Test: Try to start a second instance, observe failure
Change-Id: Id02a831b249f6432b22741dbf5a5dc3919c3df03
diff --git a/compos/composd/src/odrefresh_task.rs b/compos/composd/src/odrefresh_task.rs
index 07ede3c..8fd574c 100644
--- a/compos/composd/src/odrefresh_task.rs
+++ b/compos/composd/src/odrefresh_task.rs
@@ -60,7 +60,7 @@
struct RunningTask {
callback: Strong<dyn ICompilationTaskCallback>,
#[allow(dead_code)] // Keeps the CompOS VM alive
- comp_os: Arc<CompOsInstance>,
+ comp_os: CompOsInstance,
}
impl OdrefreshTask {
@@ -72,7 +72,7 @@
}
pub fn start(
- comp_os: Arc<CompOsInstance>,
+ comp_os: CompOsInstance,
compilation_mode: CompilationMode,
target_dir_name: String,
callback: &Strong<dyn ICompilationTaskCallback>,
@@ -98,11 +98,8 @@
let task = self.take();
// We don't do the callback if cancel has already happened.
if let Some(RunningTask { callback, comp_os }) = task {
- // If we are the last owners of the instance (and we probably are), then we
- // shut it down now, so that logs get written.
- let comp_os = Arc::try_unwrap(comp_os);
// Make sure we keep our service alive until we have called the callback.
- let lazy_service_guard = comp_os.map(CompOsInstance::shutdown);
+ let lazy_service_guard = comp_os.shutdown();
let result = match exit_code {
Ok(ExitCode::CompilationSuccess) => {