Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
Fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvie committed Jan 5, 2024
1 parent 4854a20 commit 96d5b35
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,36 @@ impl OrgFreedesktopScreenSaver for Arc<Mutex<OrgFreedesktopScreenSaverServer>> {
application_name: String,
reason_for_inhibit: String,
) -> Result<(u32,), dbus::MethodErr> {
let inhibitor = self.lock().unwrap().inhibit_manager.create_inhibitor();
if let Err(e) = inhibitor {
log::error!("Failed to create inhibitor: {:?}", e);
return Err(dbus::MethodErr::failed(&format!(
"Failed to create inhibitor: {:?}",
e
)));
}
log::info!(
"Inhibiting screensaver for {:?} because {:?}",
"Inhibiting screensaver for {:?} because {:?}.",
application_name,
reason_for_inhibit
);
match self.lock().unwrap().inhibit_manager.create_inhibitor() {
Ok(inhibitor) => Ok((self.lock().unwrap().insert_inhibitor(StoredInhibitor {
inhibitor,
name: application_name,
reason: reason_for_inhibit,
}),)),
Err(e) => {
log::error!("Failed to create inhibitor: {:?}", e);
Err(dbus::MethodErr::failed(&format!(
"Failed to create inhibitor: {:?}",
e
)))
}
}
let cookie = self.lock().unwrap().insert_inhibitor(StoredInhibitor {
inhibitor: inhibitor.unwrap(),
name: application_name,
reason: reason_for_inhibit,
});
log::info!("Inhibitor cookie is {:?}", cookie);
return Ok((cookie,));
}

fn un_inhibit(&mut self, cookie: u32) -> Result<(), dbus::MethodErr> {
log::info!("Uninhibiting {:?}", cookie);
let inhibitor = self.lock().unwrap().inhibitors_by_cookie.remove(&cookie);
match inhibitor {
None => {
Err(dbus::MethodErr::failed(&format!(
"No inhibitor with cookie {}",
cookie
)))
},
return match inhibitor {
None => Err(dbus::MethodErr::failed(&format!(
"No inhibitor with cookie {}",
cookie
))),
Some(inhibitor) => {
match self
.lock()
Expand All @@ -99,7 +98,7 @@ impl OrgFreedesktopScreenSaver for Arc<Mutex<OrgFreedesktopScreenSaverServer>> {
}
}
}
}
};
}
}

Expand Down

0 comments on commit 96d5b35

Please sign in to comment.