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

refactor: Use the simplified locks in the encryption tasks #4507

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions crates/matrix-sdk/src/encryption/backups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ impl Backups {
room_id: OwnedRoomId,
event: Raw<OriginalSyncRoomEncryptedEvent>,
) {
let tasks = self.client.inner.e2ee.tasks.lock().unwrap();
let tasks = self.client.inner.e2ee.tasks.lock();
if let Some(task) = tasks.download_room_keys.as_ref() {
task.trigger_download_for_utd_event(room_id, event);
}
Expand All @@ -1016,7 +1016,7 @@ impl Backups {
/// Send a notification to the task which is responsible for uploading room
/// keys to the backup that it might have new room keys to back up.
pub(crate) fn maybe_trigger_backup(&self) {
let tasks = self.client.inner.e2ee.tasks.lock().unwrap();
let tasks = self.client.inner.e2ee.tasks.lock();

if let Some(tasks) = tasks.upload_room_keys.as_ref() {
tasks.trigger_upload();
Expand Down
12 changes: 6 additions & 6 deletions crates/matrix-sdk/src/encryption/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{
io::{Cursor, Read, Write},
iter,
path::PathBuf,
sync::{Arc, Mutex as StdMutex},
sync::Arc,
};

use eyeball::{SharedObservable, Subscriber};
Expand All @@ -37,7 +37,7 @@ use matrix_sdk_base::crypto::{
},
CrossSigningBootstrapRequests, OlmMachine,
};
use matrix_sdk_common::executor::spawn;
use matrix_sdk_common::{executor::spawn, locks::Mutex as StdMutex};
use ruma::{
api::client::{
keys::{
Expand Down Expand Up @@ -131,7 +131,7 @@ impl EncryptionData {
pub fn initialize_room_key_tasks(&self, client: &Arc<ClientInner>) {
let weak_client = WeakClient::from_inner(client);

let mut tasks = self.tasks.lock().unwrap();
let mut tasks = self.tasks.lock();
tasks.upload_room_keys = Some(BackupUploadingTask::new(weak_client.clone()));

if self.encryption_settings.backup_download_strategy
Expand All @@ -147,7 +147,7 @@ impl EncryptionData {
/// This should happen after the usual tasks have been set up and after the
/// E2EE initialization tasks have been set up.
pub fn initialize_recovery_state_update_task(&self, client: &Client) {
let mut guard = self.tasks.lock().unwrap();
let mut guard = self.tasks.lock();

let future = Recovery::update_state_after_backup_state_change(client);
let join_handle = spawn(future);
Expand Down Expand Up @@ -1653,7 +1653,7 @@ impl Encryption {
/// allow for the initial upload of cross-signing keys without
/// authentication, rendering this parameter obsolete.
pub(crate) fn spawn_initialization_task(&self, auth_data: Option<AuthData>) {
let mut tasks = self.client.inner.e2ee.tasks.lock().unwrap();
let mut tasks = self.client.inner.e2ee.tasks.lock();

let this = self.clone();
tasks.setup_e2ee = Some(spawn(async move {
Expand All @@ -1679,7 +1679,7 @@ impl Encryption {
/// Waits for end-to-end encryption initialization tasks to finish, if any
/// was running in the background.
pub async fn wait_for_e2ee_initialization_tasks(&self) {
let task = self.client.inner.e2ee.tasks.lock().unwrap().setup_e2ee.take();
let task = self.client.inner.e2ee.tasks.lock().setup_e2ee.take();

if let Some(task) = task {
if let Err(err) = task.await {
Expand Down
Loading