Skip to content

Commit

Permalink
fix(core): kill deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Jul 21, 2024
1 parent 0af5a13 commit f8d7863
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions nyanpasu-utils/src/core/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ impl CoreInstance {

/// Kill the instance, it is a blocking operation
pub fn kill(&self) -> Result<(), CoreInstanceError> {
let instance = self.instance.lock();
if instance.is_none() {
let mut instance_holder = self.instance.lock();
if instance_holder.is_none() {
return Err(CoreInstanceError::StateCheckFailed);
}
let instance = instance.as_ref().unwrap();
let instance = instance_holder.as_ref().unwrap();
instance.kill()?;
loop {
if let Some(state) = instance.try_wait()? {
Expand All @@ -277,10 +277,9 @@ impl CoreInstance {
}
std::thread::sleep(std::time::Duration::from_millis(10));
}
*instance_holder = None;
{
let mut instance = self.instance.lock();
let mut state = self.state.write();
*instance = None;
*state = CoreInstanceState::Stopped;
}
Ok(())
Expand Down

0 comments on commit f8d7863

Please sign in to comment.