fix: launch with the selected JVM and own subprocess lifetimes
This commit is contained in:
1 parent
eb436c2ab8
commit
dc351df546
31 files changed
+3061
-820
No files matched your search
+23
-4
@@ -17,14 +17,11 @@ pub enum RunState {
|
||||
pub static RUNNING: LazyLock<Arc<Mutex<HashMap<String, RunState>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||
|
||||
// queued up so the TUI event loop can flush these to disk in batch,
|
||||
// the child process monitor shouldn't be writing config files directly
|
||||
// The monitor persists timestamps; the TUI drains these to update its cached instances.
|
||||
type PendingLastPlayed = Arc<Mutex<Vec<(String, DateTime<Utc>)>>>;
|
||||
pub static PENDING_LAST_PLAYED: LazyLock<PendingLastPlayed> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(Vec::new())));
|
||||
|
||||
// oneshot channels to signal a running instance to stop.
|
||||
// send_kill fires the channel, the launch task receives it and kills the child process.
|
||||
type KillSenders = Arc<Mutex<HashMap<String, tokio::sync::oneshot::Sender<()>>>>;
|
||||
pub static KILL_SENDERS: LazyLock<KillSenders> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||
@@ -114,6 +111,28 @@ pub fn cleanup_kill_sender(name: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn lock_instance(
|
||||
root: &std::path::Path,
|
||||
name: &str,
|
||||
) -> Result<std::fs::File, crate::instance::manager::InstanceError> {
|
||||
crate::instance::manager::validate_name(name)?;
|
||||
let locks = root.join(".rmcl-locks");
|
||||
std::fs::create_dir_all(&locks)?;
|
||||
let file = std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.truncate(false)
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(locks.join(format!("{name}.lock")))?;
|
||||
match file.try_lock() {
|
||||
Ok(()) => Ok(file),
|
||||
Err(std::fs::TryLockError::WouldBlock) => Err(
|
||||
crate::instance::manager::InstanceError::InstanceRunning(name.to_owned()),
|
||||
),
|
||||
Err(std::fs::TryLockError::Error(error)) => Err(error.into()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/runtime.rs"]
|
||||
mod tests;
|
||||
Reference in new issue
Block a user