Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Avoid calling await while holding a lock #663

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions rust/agama-dbus-server/src/network/dbus/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,18 @@ impl Tree {
///
/// * `id`: connection ID.
pub async fn remove_connection(&mut self, id: &str) -> Result<(), ServiceError> {
let mut objects = self.objects.lock();
let Some(path) = objects.connection_path(id) else {
return Ok(())
};
self.remove_connection_on(path.as_str()).await?;
objects.deregister_connection(id).unwrap();
let cloned_path;

{
let mut objects = self.objects.lock();
let Some(path) = objects.connection_path(id) else {
return Ok(())
};
cloned_path = path.to_string();
objects.deregister_connection(id).unwrap();
}

self.remove_connection_on(&cloned_path).await?;
Ok(())
}

Expand All @@ -142,24 +148,32 @@ impl Tree {

/// Clears all the connections from the tree.
async fn remove_connections(&self) -> Result<(), ServiceError> {
let mut objects = self.objects.lock();
for path in objects.connections.values() {
let paths: Vec<_>;
{
let mut objects = self.objects.lock();
objects.connections.clear();
paths = objects.connections.values().cloned().collect();
}
for path in paths {
self.remove_connection_on(path.as_str()).await?;
}
objects.connections.clear();
Ok(())
}

/// Clears all the devices from the tree.
async fn remove_devices(&mut self) -> Result<(), ServiceError> {
let paths: Vec<_>;
let object_server = self.connection.object_server();
let mut objects = self.objects.lock();
for path in objects.devices.values() {
{
let mut objects = self.objects.lock();
objects.devices.clear();
paths = objects.connections.values().cloned().collect();
}
for path in paths {
object_server
.remove::<interfaces::Device, _>(path.as_str())
.await?;
}
objects.devices.clear();
Ok(())
}

Expand Down
Loading