Small optimisations in the systemd module.
This commit is contained in:
parent
843cd69eb4
commit
527e0269ff
1 changed files with 9 additions and 15 deletions
|
|
@ -15,9 +15,7 @@ use dbus::{
|
||||||
Message, Path,
|
Message, Path,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
rc::Rc,
|
|
||||||
result::Result,
|
result::Result,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
sync::{
|
sync::{
|
||||||
|
|
@ -31,7 +29,7 @@ const SD_DESTINATION: &str = "org.freedesktop.systemd1";
|
||||||
const SD_PATH: &str = "/org/freedesktop/systemd1";
|
const SD_PATH: &str = "/org/freedesktop/systemd1";
|
||||||
|
|
||||||
pub struct ServiceManager {
|
pub struct ServiceManager {
|
||||||
proxy: Proxy<'static, Rc<Connection>>,
|
proxy: Proxy<'static, Box<Connection>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UnitManager<'a> {
|
pub struct UnitManager<'a> {
|
||||||
|
|
@ -78,8 +76,8 @@ pub struct Job<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct JobMonitor {
|
pub struct JobMonitor {
|
||||||
job_names: Arc<Mutex<HashSet<String>>>,
|
job_names: Arc<Mutex<im::HashSet<String>>>,
|
||||||
tokens: HashSet<Token>,
|
tokens: im::HashSet<Token>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for ServiceManager {
|
impl Drop for ServiceManager {
|
||||||
|
|
@ -95,7 +93,7 @@ impl ServiceManager {
|
||||||
SD_DESTINATION,
|
SD_DESTINATION,
|
||||||
SD_PATH,
|
SD_PATH,
|
||||||
Duration::from_secs(2),
|
Duration::from_secs(2),
|
||||||
Rc::new(conn),
|
Box::new(conn),
|
||||||
);
|
);
|
||||||
|
|
||||||
OrgFreedesktopSystemd1Manager::subscribe(&proxy)?;
|
OrgFreedesktopSystemd1Manager::subscribe(&proxy)?;
|
||||||
|
|
@ -149,7 +147,7 @@ impl ServiceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn monitor_jobs_init(&self) -> Result<JobMonitor, Error> {
|
pub fn monitor_jobs_init(&self) -> Result<JobMonitor, Error> {
|
||||||
let job_names: Arc<Mutex<HashSet<String>>> = Arc::new(Mutex::from(HashSet::new()));
|
let job_names: Arc<Mutex<im::HashSet<String>>> = Arc::new(Mutex::from(im::HashSet::new()));
|
||||||
|
|
||||||
let job_names_clone = Arc::clone(&job_names);
|
let job_names_clone = Arc::clone(&job_names);
|
||||||
let token = self.proxy.match_signal(
|
let token = self.proxy.match_signal(
|
||||||
|
|
@ -166,7 +164,7 @@ impl ServiceManager {
|
||||||
|
|
||||||
Ok(JobMonitor {
|
Ok(JobMonitor {
|
||||||
job_names: Arc::clone(&job_names),
|
job_names: Arc::clone(&job_names),
|
||||||
tokens: HashSet::from([token]),
|
tokens: im::HashSet::unit(token),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,7 +182,7 @@ impl ServiceManager {
|
||||||
{
|
{
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
|
|
||||||
let mut waiting_for: HashSet<String> = services
|
let mut waiting_for: im::HashSet<String> = services
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|n| String::from(n.as_ref()))
|
.map(|n| String::from(n.as_ref()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
@ -206,12 +204,8 @@ impl ServiceManager {
|
||||||
{
|
{
|
||||||
let mut job_names = job_monitor.job_names.lock().unwrap();
|
let mut job_names = job_monitor.job_names.lock().unwrap();
|
||||||
if !job_names.is_empty() {
|
if !job_names.is_empty() {
|
||||||
waiting_for = waiting_for
|
waiting_for = waiting_for.difference(job_names.clone());
|
||||||
.difference(&job_names)
|
*job_names = im::HashSet::new();
|
||||||
// FIXME can we avoid copying here?
|
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect();
|
|
||||||
*job_names = HashSet::new();
|
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"Waiting for jobs to finish... ({:?}/{:?})",
|
"Waiting for jobs to finish... ({:?}/{:?})",
|
||||||
total_jobs - waiting_for.len(),
|
total_jobs - waiting_for.len(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue