diff --git a/Cargo.lock b/Cargo.lock index 910987a9c..ab79b39ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2836,7 +2836,6 @@ dependencies = [ name = "matrix-sdk-common" version = "0.6.0" dependencies = [ - "async-lock", "futures-core", "futures-util", "gloo-timers", @@ -3020,6 +3019,7 @@ dependencies = [ "serde", "serde_json", "thiserror", + "tokio", "tracing", "uuid", "wasm-bindgen", diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index f4912d2df..6cdcead91 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -109,7 +109,7 @@ pub struct Client { pub(crate) client: MatrixClient, delegate: Arc>>>, session_verification_controller: - Arc>>, + Arc>>, /// The sliding sync proxy that the client is configured to use by default. /// If this value is `Some`, it will be automatically added to the builder /// when calling `sliding_sync()`. @@ -120,7 +120,7 @@ pub struct Client { impl Client { pub fn new(client: MatrixClient) -> Self { let session_verification_controller: Arc< - matrix_sdk::locks::RwLock>, + tokio::sync::RwLock>, > = Default::default(); let ctrl = session_verification_controller.clone(); diff --git a/crates/matrix-sdk-appservice/src/event_handler.rs b/crates/matrix-sdk-appservice/src/event_handler.rs index 830eb661f..5c7d7de8f 100644 --- a/crates/matrix-sdk-appservice/src/event_handler.rs +++ b/crates/matrix-sdk-appservice/src/event_handler.rs @@ -14,7 +14,7 @@ use std::{future::Future, pin::Pin, sync::Arc}; -use matrix_sdk::locks::Mutex; +use tokio::sync::Mutex; use crate::{ ruma::api::appservice::query::{ diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index ec210d304..2e24fe0f1 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -43,6 +43,7 @@ once_cell = { workspace = true } ruma = { workspace = true, features = ["canonical-json"] } serde = { workspace = true, features = ["rc"] } serde_json = { workspace = true } +tokio = { version = "1.24", default-features = false, features = ["sync"] } thiserror = { workspace = true } tracing = { workspace = true } zeroize = { workspace = true, features = ["zeroize_derive"] } diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index 8be3af224..10305e5ac 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -22,7 +22,7 @@ use std::{ use std::{ops::Deref, sync::Arc}; use eyeball::Subscriber; -use matrix_sdk_common::{instant::Instant, locks::RwLock}; +use matrix_sdk_common::instant::Instant; #[cfg(feature = "e2e-encryption")] use matrix_sdk_crypto::{ store::DynCryptoStore, EncryptionSettings, OlmError, OlmMachine, ToDeviceRequest, @@ -53,6 +53,7 @@ use ruma::{ serde::Raw, MilliSecondsSinceUnixEpoch, OwnedUserId, RoomId, UInt, UserId, }; +use tokio::sync::RwLock; use tracing::{debug, info, trace, warn}; #[cfg(feature = "e2e-encryption")] diff --git a/crates/matrix-sdk-base/src/store/memory_store.rs b/crates/matrix-sdk-base/src/store/memory_store.rs index 81b35e886..253404530 100644 --- a/crates/matrix-sdk-base/src/store/memory_store.rs +++ b/crates/matrix-sdk-base/src/store/memory_store.rs @@ -19,8 +19,7 @@ use std::{ use async_trait::async_trait; use dashmap::{DashMap, DashSet}; -#[allow(unused_imports)] -use matrix_sdk_common::{instant::Instant, locks::Mutex}; +use matrix_sdk_common::instant::Instant; use ruma::{ canonical_json::redact, events::{ @@ -117,7 +116,7 @@ impl MemoryStore { room_user_receipts: Default::default(), room_event_receipts: Default::default(), #[cfg(feature = "memory-media-cache")] - media: Arc::new(Mutex::new(LruCache::new( + media: Arc::new(tokio::sync::Mutex::new(LruCache::new( 100.try_into().expect("100 is a non-zero usize"), ))), custom: DashMap::new().into(), diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index 35a0cdb41..bdadb6509 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -39,7 +39,6 @@ pub mod integration_tests; mod traits; use dashmap::DashMap; -use matrix_sdk_common::locks::RwLock; #[cfg(feature = "e2e-encryption")] use matrix_sdk_crypto::store::{DynCryptoStore, IntoCryptoStore}; pub use matrix_sdk_store_encryption::Error as StoreEncryptionError; @@ -58,6 +57,7 @@ use ruma::{ serde::Raw, EventId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId, }; +use tokio::sync::RwLock; /// BoxStream of owned Types pub type BoxStream = Pin + Send>>; diff --git a/crates/matrix-sdk-common/Cargo.toml b/crates/matrix-sdk-common/Cargo.toml index 9682fe8c2..ccb4161c6 100644 --- a/crates/matrix-sdk-common/Cargo.toml +++ b/crates/matrix-sdk-common/Cargo.toml @@ -26,7 +26,6 @@ serde = { workspace = true } serde_json = { workspace = true } [target.'cfg(target_arch = "wasm32")'.dependencies] -async-lock = "2.5.0" futures-util = { workspace = true, features = ["channel"] } wasm-bindgen-futures = { version = "0.4.33", optional = true } gloo-timers = { version = "0.2.6", features = ["futures"] } diff --git a/crates/matrix-sdk-common/src/lib.rs b/crates/matrix-sdk-common/src/lib.rs index 687e0ee13..51104a021 100644 --- a/crates/matrix-sdk-common/src/lib.rs +++ b/crates/matrix-sdk-common/src/lib.rs @@ -5,7 +5,6 @@ pub use instant; pub mod deserialized_responses; pub mod executor; -pub mod locks; pub mod timeout; /// Alias for `Send` on non-wasm, empty trait (implemented by everything) on diff --git a/crates/matrix-sdk-common/src/locks.rs b/crates/matrix-sdk-common/src/locks.rs deleted file mode 100644 index fbb89f52d..000000000 --- a/crates/matrix-sdk-common/src/locks.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[cfg(target_arch = "wasm32")] -pub use async_lock::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; -#[cfg(not(target_arch = "wasm32"))] -pub use tokio::sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; diff --git a/crates/matrix-sdk-crypto/Cargo.toml b/crates/matrix-sdk-crypto/Cargo.toml index 4ac80533f..f39982698 100644 --- a/crates/matrix-sdk-crypto/Cargo.toml +++ b/crates/matrix-sdk-crypto/Cargo.toml @@ -58,6 +58,9 @@ vodozemac = { workspace = true } zeroize = { workspace = true, features = ["zeroize_derive"] } cfg-if = "1.0" +[target.'cfg(target_arch = "wasm32")'.dependencies] +tokio = { version = "1.24", default-features = false, features = ["sync"] } + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1.24", default-features = false, features = ["time"] } diff --git a/crates/matrix-sdk-crypto/src/backups/mod.rs b/crates/matrix-sdk-crypto/src/backups/mod.rs index 03eb8817b..b682e1fb1 100644 --- a/crates/matrix-sdk-crypto/src/backups/mod.rs +++ b/crates/matrix-sdk-crypto/src/backups/mod.rs @@ -28,11 +28,11 @@ use std::{ sync::Arc, }; -use matrix_sdk_common::locks::RwLock; use ruma::{ api::client::backup::RoomKeyBackup, serde::Raw, DeviceId, DeviceKeyAlgorithm, OwnedDeviceId, OwnedRoomId, OwnedTransactionId, TransactionId, }; +use tokio::sync::RwLock; use tracing::{debug, info, instrument, trace, warn}; use crate::{ diff --git a/crates/matrix-sdk-crypto/src/gossiping/machine.rs b/crates/matrix-sdk-crypto/src/gossiping/machine.rs index ee77ba127..b78fd012f 100644 --- a/crates/matrix-sdk-crypto/src/gossiping/machine.rs +++ b/crates/matrix-sdk-crypto/src/gossiping/machine.rs @@ -1039,7 +1039,6 @@ mod tests { #[cfg(feature = "automatic-room-key-forwarding")] use assert_matches::assert_matches; use dashmap::DashMap; - use matrix_sdk_common::locks::Mutex; use matrix_sdk_test::async_test; use ruma::{ device_id, event_id, @@ -1054,6 +1053,7 @@ mod tests { #[cfg(feature = "automatic-room-key-forwarding")] use serde::{de::DeserializeOwned, Serialize}; use serde_json::json; + use tokio::sync::Mutex; use super::GossipMachine; #[cfg(feature = "automatic-room-key-forwarding")] diff --git a/crates/matrix-sdk-crypto/src/identities/device.rs b/crates/matrix-sdk-crypto/src/identities/device.rs index d33d9159a..2c14e3e3c 100644 --- a/crates/matrix-sdk-crypto/src/identities/device.rs +++ b/crates/matrix-sdk-crypto/src/identities/device.rs @@ -23,7 +23,6 @@ use std::{ }; use atomic::Atomic; -use matrix_sdk_common::locks::Mutex; use ruma::{ api::client::keys::upload_signatures::v3::Request as SignatureUploadRequest, events::key::verification::VerificationMethod, serde::Raw, DeviceId, DeviceKeyAlgorithm, @@ -31,6 +30,7 @@ use ruma::{ }; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde_json::Value; +use tokio::sync::Mutex; use tracing::{trace, warn}; use vodozemac::{olm::SessionConfig, Curve25519PublicKey, Ed25519PublicKey}; diff --git a/crates/matrix-sdk-crypto/src/identities/manager.rs b/crates/matrix-sdk-crypto/src/identities/manager.rs index c2c842b52..b87d61221 100644 --- a/crates/matrix-sdk-crypto/src/identities/manager.rs +++ b/crates/matrix-sdk-crypto/src/identities/manager.rs @@ -20,12 +20,13 @@ use std::{ use futures_util::future::join_all; use itertools::Itertools; -use matrix_sdk_common::{executor::spawn, locks::Mutex}; +use matrix_sdk_common::executor::spawn; use ruma::{ api::client::keys::get_keys::v3::Response as KeysQueryResponse, serde::Raw, DeviceId, OwnedDeviceId, OwnedServerName, OwnedTransactionId, OwnedUserId, ServerName, TransactionId, UserId, }; +use tokio::sync::Mutex; use tracing::{debug, info, instrument, trace, warn}; use crate::{ @@ -718,12 +719,12 @@ pub(crate) mod testing { #![allow(dead_code)] use std::sync::Arc; - use matrix_sdk_common::locks::Mutex; use ruma::{ api::{client::keys::get_keys::v3::Response as KeyQueryResponse, IncomingResponse}, device_id, user_id, DeviceId, UserId, }; use serde_json::json; + use tokio::sync::Mutex; use crate::{ identities::IdentityManager, diff --git a/crates/matrix-sdk-crypto/src/identities/user.rs b/crates/matrix-sdk-crypto/src/identities/user.rs index 8afc59545..2aea2c545 100644 --- a/crates/matrix-sdk-crypto/src/identities/user.rs +++ b/crates/matrix-sdk-crypto/src/identities/user.rs @@ -702,10 +702,10 @@ pub(crate) mod tests { use std::sync::Arc; use assert_matches::assert_matches; - use matrix_sdk_common::locks::Mutex; use matrix_sdk_test::async_test; use ruma::user_id; use serde_json::{json, Value}; + use tokio::sync::Mutex; use super::{ testing::{device, get_other_identity, get_own_identity}, diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 68660fe29..29a92cddc 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -19,12 +19,9 @@ use std::{ }; use dashmap::DashMap; -use matrix_sdk_common::{ - deserialized_responses::{ - AlgorithmInfo, DeviceLinkProblem, EncryptionInfo, TimelineEvent, VerificationLevel, - VerificationState, - }, - locks::Mutex, +use matrix_sdk_common::deserialized_responses::{ + AlgorithmInfo, DeviceLinkProblem, EncryptionInfo, TimelineEvent, VerificationLevel, + VerificationState, }; use ruma::{ api::client::{ @@ -45,6 +42,7 @@ use ruma::{ RoomId, TransactionId, UInt, UserId, }; use serde_json::{value::to_raw_value, Value}; +use tokio::sync::Mutex; use tracing::{ debug, error, field::{debug, display}, diff --git a/crates/matrix-sdk-crypto/src/olm/account.rs b/crates/matrix-sdk-crypto/src/olm/account.rs index 07955615f..a816409f3 100644 --- a/crates/matrix-sdk-crypto/src/olm/account.rs +++ b/crates/matrix-sdk-crypto/src/olm/account.rs @@ -22,7 +22,6 @@ use std::{ }, }; -use matrix_sdk_common::locks::Mutex; use ruma::{ api::client::keys::{ upload_keys, @@ -36,6 +35,7 @@ use ruma::{ use serde::{Deserialize, Serialize}; use serde_json::{value::RawValue as RawJsonValue, Value}; use sha2::{Digest, Sha256}; +use tokio::sync::Mutex; use tracing::{debug, info, instrument, trace, warn, Span}; use vodozemac::{ olm::{ diff --git a/crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs b/crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs index 3e36f855a..38a1b19ba 100644 --- a/crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs +++ b/crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs @@ -21,7 +21,6 @@ use std::{ }, }; -use matrix_sdk_common::locks::Mutex; use ruma::{ events::{room::history_visibility::HistoryVisibility, AnyTimelineEvent}, serde::Raw, @@ -29,6 +28,7 @@ use ruma::{ }; use serde::{Deserialize, Serialize}; use serde_json::Value; +use tokio::sync::Mutex; use vodozemac::{ megolm::{ DecryptedMessage, DecryptionError, InboundGroupSession as InnerSession, diff --git a/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs b/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs index ddef13791..22d63ee2f 100644 --- a/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs +++ b/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs @@ -24,7 +24,6 @@ use std::{ }; use dashmap::DashMap; -use matrix_sdk_common::locks::RwLock; use ruma::{ events::room::{encryption::RoomEncryptionEventContent, history_visibility::HistoryVisibility}, serde::Raw, @@ -33,6 +32,7 @@ use ruma::{ }; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; +use tokio::sync::RwLock; use tracing::{debug, error, info}; use vodozemac::{megolm::SessionConfig, Curve25519PublicKey}; pub use vodozemac::{ diff --git a/crates/matrix-sdk-crypto/src/olm/session.rs b/crates/matrix-sdk-crypto/src/olm/session.rs index aa3919107..266c23fae 100644 --- a/crates/matrix-sdk-crypto/src/olm/session.rs +++ b/crates/matrix-sdk-crypto/src/olm/session.rs @@ -14,10 +14,10 @@ use std::{fmt, sync::Arc}; -use matrix_sdk_common::locks::Mutex; use ruma::{serde::Raw, DeviceId, SecondsSinceUnixEpoch, UserId}; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; +use tokio::sync::Mutex; use vodozemac::{ olm::{DecryptionError, OlmMessage, Session as InnerSession, SessionConfig, SessionPickle}, Curve25519PublicKey, diff --git a/crates/matrix-sdk-crypto/src/olm/signing/mod.rs b/crates/matrix-sdk-crypto/src/olm/signing/mod.rs index 300ce488f..d94720032 100644 --- a/crates/matrix-sdk-crypto/src/olm/signing/mod.rs +++ b/crates/matrix-sdk-crypto/src/olm/signing/mod.rs @@ -19,7 +19,6 @@ use std::sync::{ Arc, }; -use matrix_sdk_common::locks::Mutex; use pk_signing::{MasterSigning, PickledSignings, SelfSigning, Signing, SigningError, UserSigning}; use ruma::{ api::client::keys::upload_signatures::v3::{Request as SignatureUploadRequest, SignedKeys}, @@ -28,6 +27,7 @@ use ruma::{ DeviceKeyAlgorithm, DeviceKeyId, OwnedDeviceId, OwnedDeviceKeyId, OwnedUserId, UserId, }; use serde::{Deserialize, Serialize}; +use tokio::sync::Mutex; use vodozemac::Ed25519Signature; use crate::{ diff --git a/crates/matrix-sdk-crypto/src/session_manager/sessions.rs b/crates/matrix-sdk-crypto/src/session_manager/sessions.rs index 7dc021fb2..549a38cab 100644 --- a/crates/matrix-sdk-crypto/src/session_manager/sessions.rs +++ b/crates/matrix-sdk-crypto/src/session_manager/sessions.rs @@ -397,7 +397,6 @@ mod tests { use std::{collections::BTreeMap, iter, ops::Deref, sync::Arc}; use dashmap::DashMap; - use matrix_sdk_common::locks::Mutex; use matrix_sdk_test::{async_test, response_from_file}; use ruma::{ api::{ @@ -410,6 +409,7 @@ mod tests { device_id, user_id, DeviceId, UserId, }; use serde_json::json; + use tokio::sync::Mutex; use tracing::info; use super::SessionManager; diff --git a/crates/matrix-sdk-crypto/src/store/caches.rs b/crates/matrix-sdk-crypto/src/store/caches.rs index 04602135f..2caabf948 100644 --- a/crates/matrix-sdk-crypto/src/store/caches.rs +++ b/crates/matrix-sdk-crypto/src/store/caches.rs @@ -25,8 +25,8 @@ use std::{ use atomic::Ordering; use dashmap::DashMap; -use matrix_sdk_common::locks::Mutex; use ruma::{DeviceId, OwnedDeviceId, OwnedRoomId, OwnedUserId, RoomId, UserId}; +use tokio::sync::Mutex; use tracing::{field::display, instrument, trace, Span}; use crate::{ diff --git a/crates/matrix-sdk-crypto/src/store/memorystore.rs b/crates/matrix-sdk-crypto/src/store/memorystore.rs index 7d3126435..0b1d45661 100644 --- a/crates/matrix-sdk-crypto/src/store/memorystore.rs +++ b/crates/matrix-sdk-crypto/src/store/memorystore.rs @@ -16,10 +16,10 @@ use std::{collections::HashMap, convert::Infallible, sync::Arc}; use async_trait::async_trait; use dashmap::{DashMap, DashSet}; -use matrix_sdk_common::locks::Mutex; use ruma::{ DeviceId, OwnedDeviceId, OwnedTransactionId, OwnedUserId, RoomId, TransactionId, UserId, }; +use tokio::sync::Mutex; use tracing::warn; use super::{ diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index 5b60fe226..616864b68 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -49,12 +49,12 @@ use std::{ use async_std::sync::{Condvar, Mutex as AsyncStdMutex}; use atomic::Ordering; use dashmap::DashSet; -use matrix_sdk_common::locks::Mutex; use ruma::{ events::secret::request::SecretName, DeviceId, OwnedDeviceId, OwnedRoomId, OwnedUserId, UserId, }; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use thiserror::Error; +use tokio::sync::Mutex; use tracing::{info, warn}; use vodozemac::{megolm::SessionOrdering, Curve25519PublicKey}; use zeroize::Zeroize; diff --git a/crates/matrix-sdk-crypto/src/store/traits.rs b/crates/matrix-sdk-crypto/src/store/traits.rs index 43d7021b2..58cfed790 100644 --- a/crates/matrix-sdk-crypto/src/store/traits.rs +++ b/crates/matrix-sdk-crypto/src/store/traits.rs @@ -15,8 +15,9 @@ use std::{collections::HashMap, fmt, sync::Arc}; use async_trait::async_trait; -use matrix_sdk_common::{locks::Mutex, AsyncTraitDeps}; +use matrix_sdk_common::AsyncTraitDeps; use ruma::{DeviceId, OwnedDeviceId, RoomId, TransactionId, UserId}; +use tokio::sync::Mutex; use super::{BackupKeys, Changes, CryptoStoreError, Result, RoomKeyCounts, RoomSettings}; use crate::{ diff --git a/crates/matrix-sdk-crypto/src/verification/machine.rs b/crates/matrix-sdk-crypto/src/verification/machine.rs index fac58db70..e7374d83f 100644 --- a/crates/matrix-sdk-crypto/src/verification/machine.rs +++ b/crates/matrix-sdk-crypto/src/verification/machine.rs @@ -18,7 +18,6 @@ use std::{ }; use dashmap::DashMap; -use matrix_sdk_common::locks::Mutex; use ruma::{ events::{ key::verification::VerificationMethod, AnyToDeviceEvent, AnyToDeviceEventContent, @@ -28,6 +27,7 @@ use ruma::{ uint, DeviceId, EventId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId, SecondsSinceUnixEpoch, TransactionId, UInt, UserId, }; +use tokio::sync::Mutex; use tracing::{debug, info, instrument, trace, warn}; use super::{ @@ -527,9 +527,9 @@ impl VerificationMachine { mod tests { use std::sync::Arc; - use matrix_sdk_common::locks::Mutex; use matrix_sdk_test::async_test; use ruma::TransactionId; + use tokio::sync::Mutex; use super::{Sas, VerificationMachine}; use crate::{ diff --git a/crates/matrix-sdk-crypto/src/verification/mod.rs b/crates/matrix-sdk-crypto/src/verification/mod.rs index ed97fb857..d68099981 100644 --- a/crates/matrix-sdk-crypto/src/verification/mod.rs +++ b/crates/matrix-sdk-crypto/src/verification/mod.rs @@ -24,7 +24,6 @@ use std::{collections::HashMap, ops::Deref, sync::Arc}; use event_enums::OutgoingContent; pub use machine::VerificationMachine; -use matrix_sdk_common::locks::Mutex; #[cfg(feature = "qrcode")] pub use qrcode::{QrVerification, QrVerificationState, ScanError}; pub use requests::{VerificationRequest, VerificationRequestState}; @@ -46,6 +45,7 @@ use ruma::{ UserId, }; pub use sas::{AcceptSettings, AcceptedProtocols, EmojiShortAuthString, Sas, SasState}; +use tokio::sync::Mutex; use tracing::{error, info, trace, warn}; use crate::{ @@ -812,8 +812,8 @@ pub(crate) mod tests { #[cfg(test)] mod test { - use matrix_sdk_common::locks::Mutex; use ruma::{device_id, user_id, DeviceId, UserId}; + use tokio::sync::Mutex; use super::VerificationStore; use crate::{ diff --git a/crates/matrix-sdk-crypto/src/verification/qrcode.rs b/crates/matrix-sdk-crypto/src/verification/qrcode.rs index f9f999dd1..b1de26fe9 100644 --- a/crates/matrix-sdk-crypto/src/verification/qrcode.rs +++ b/crates/matrix-sdk-crypto/src/verification/qrcode.rs @@ -847,10 +847,10 @@ mod tests { use std::sync::Arc; use assert_matches::assert_matches; - use matrix_sdk_common::locks::Mutex; use matrix_sdk_qrcode::QrVerificationData; use matrix_sdk_test::async_test; use ruma::{device_id, event_id, room_id, user_id, DeviceId, UserId}; + use tokio::sync::Mutex; use crate::{ olm::{PrivateCrossSigningIdentity, ReadOnlyAccount}, diff --git a/crates/matrix-sdk-crypto/src/verification/sas/mod.rs b/crates/matrix-sdk-crypto/src/verification/sas/mod.rs index efdf366c2..521358c42 100644 --- a/crates/matrix-sdk-crypto/src/verification/sas/mod.rs +++ b/crates/matrix-sdk-crypto/src/verification/sas/mod.rs @@ -854,9 +854,9 @@ impl AcceptSettings { #[cfg(test)] mod tests { use assert_matches::assert_matches; - use matrix_sdk_common::locks::Mutex; use matrix_sdk_test::async_test; use ruma::{device_id, user_id, DeviceId, TransactionId, UserId}; + use tokio::sync::Mutex; use super::Sas; use crate::{ diff --git a/crates/matrix-sdk-indexeddb/Cargo.toml b/crates/matrix-sdk-indexeddb/Cargo.toml index 84247d624..c009a1f19 100644 --- a/crates/matrix-sdk-indexeddb/Cargo.toml +++ b/crates/matrix-sdk-indexeddb/Cargo.toml @@ -32,6 +32,7 @@ ruma = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } +tokio = { version = "1.24", default-features = false, features = ["sync"] } tracing = { workspace = true } wasm-bindgen = "0.2.83" web-sys = { version = "0.3.57", features = ["IdbKeyRange"] } diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store.rs b/crates/matrix-sdk-indexeddb/src/crypto_store.rs index 10116fe15..cc4b14b07 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store.rs @@ -20,7 +20,6 @@ use std::{ use async_trait::async_trait; use gloo_utils::format::JsValueSerdeExt; use indexed_db_futures::prelude::*; -use matrix_sdk_base::locks::Mutex; use matrix_sdk_crypto::{ olm::{ IdentityKeys, InboundGroupSession, OlmMessageHash, OutboundGroupSession, @@ -36,6 +35,7 @@ use matrix_sdk_crypto::{ use matrix_sdk_store_encryption::StoreCipher; use ruma::{DeviceId, OwnedDeviceId, RoomId, TransactionId, UserId}; use serde::{de::DeserializeOwned, Serialize}; +use tokio::sync::Mutex; use wasm_bindgen::JsValue; use web_sys::IdbKeyRange; diff --git a/crates/matrix-sdk-sled/src/crypto_store.rs b/crates/matrix-sdk-sled/src/crypto_store.rs index 01652fb59..b014765c3 100644 --- a/crates/matrix-sdk-sled/src/crypto_store.rs +++ b/crates/matrix-sdk-sled/src/crypto_store.rs @@ -20,7 +20,6 @@ use std::{ }; use async_trait::async_trait; -use matrix_sdk_common::locks::Mutex; use matrix_sdk_crypto::{ olm::{ IdentityKeys, InboundGroupSession, OutboundGroupSession, PickledInboundGroupSession, @@ -41,6 +40,7 @@ use sled::{ transaction::{ConflictableTransactionError, TransactionError}, Batch, Config, Db, IVec, Transactional, Tree, }; +use tokio::sync::Mutex; use tracing::debug; use super::OpenStoreError; diff --git a/crates/matrix-sdk-sqlite/src/crypto_store.rs b/crates/matrix-sdk-sqlite/src/crypto_store.rs index eedf4f013..9c689b2b3 100644 --- a/crates/matrix-sdk-sqlite/src/crypto_store.rs +++ b/crates/matrix-sdk-sqlite/src/crypto_store.rs @@ -21,7 +21,6 @@ use std::{ use async_trait::async_trait; use deadpool_sqlite::{Object as SqliteConn, Pool as SqlitePool, Runtime}; -use matrix_sdk_common::locks::Mutex; use matrix_sdk_crypto::{ olm::{ IdentityKeys, InboundGroupSession, OutboundGroupSession, PickledInboundGroupSession, @@ -35,7 +34,7 @@ use matrix_sdk_store_encryption::StoreCipher; use ruma::{DeviceId, OwnedDeviceId, RoomId, TransactionId, UserId}; use rusqlite::OptionalExtension; use serde::{de::DeserializeOwned, Serialize}; -use tokio::fs; +use tokio::{fs, sync::Mutex}; use tracing::{debug, error, instrument, warn}; use crate::{ diff --git a/crates/matrix-sdk/src/client/builder.rs b/crates/matrix-sdk/src/client/builder.rs index 8a621fba5..b275a0741 100644 --- a/crates/matrix-sdk/src/client/builder.rs +++ b/crates/matrix-sdk/src/client/builder.rs @@ -15,17 +15,13 @@ use std::{fmt, sync::Arc}; -use matrix_sdk_base::{ - locks::{Mutex, RwLock}, - store::StoreConfig, - BaseClient, -}; +use matrix_sdk_base::{store::StoreConfig, BaseClient}; use ruma::{ api::{client::discovery::discover_homeserver, error::FromHttpResponseError, MatrixVersion}, OwnedServerName, ServerName, }; use thiserror::Error; -use tokio::sync::{broadcast, OnceCell}; +use tokio::sync::{broadcast, Mutex, OnceCell, RwLock}; use tracing::{ debug, field::{self, debug}, diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index ba53e22ae..af618cce6 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -29,10 +29,7 @@ use matrix_sdk_base::{ store::DynStateStore, BaseClient, RoomState, SendOutsideWasm, Session, SessionMeta, SessionTokens, SyncOutsideWasm, }; -use matrix_sdk_common::{ - instant::Instant, - locks::{Mutex, RwLock, RwLockReadGuard}, -}; +use matrix_sdk_common::instant::Instant; #[cfg(feature = "appservice")] use ruma::TransactionId; use ruma::{ @@ -67,7 +64,7 @@ use ruma::{ ServerName, UInt, UserId, }; use serde::de::DeserializeOwned; -use tokio::sync::{broadcast, OnceCell}; +use tokio::sync::{broadcast, Mutex, OnceCell, RwLock, RwLockReadGuard}; use tracing::{debug, error, field::display, info, instrument, trace, Instrument, Span}; use url::Url; @@ -1419,12 +1416,9 @@ impl Client { /// [`UnknownToken`]: ruma::api::client::error::ErrorKind::UnknownToken /// [restore the session]: Client::restore_session pub async fn refresh_access_token(&self) -> HttpResult> { - #[cfg(not(target_arch = "wasm32"))] - let lock = self.inner.refresh_token_lock.try_lock().ok(); - #[cfg(target_arch = "wasm32")] let lock = self.inner.refresh_token_lock.try_lock(); - if let Some(mut guard) = lock { + if let Ok(mut guard) = lock { let Some(mut session_tokens) = self.session_tokens() else { *guard = Err(RefreshTokenError::RefreshTokenRequired); return Err(RefreshTokenError::RefreshTokenRequired.into()); diff --git a/crates/matrix-sdk/src/encryption/identities/users.rs b/crates/matrix-sdk/src/encryption/identities/users.rs index 619fbdab2..dd7c7043a 100644 --- a/crates/matrix-sdk/src/encryption/identities/users.rs +++ b/crates/matrix-sdk/src/encryption/identities/users.rs @@ -14,12 +14,8 @@ use std::sync::Arc; -use matrix_sdk_base::{ - crypto::{ - types::MasterPubkey, OwnUserIdentity as InnerOwnUserIdentity, - UserIdentity as InnerUserIdentity, - }, - locks::RwLock, +use matrix_sdk_base::crypto::{ + types::MasterPubkey, OwnUserIdentity as InnerOwnUserIdentity, UserIdentity as InnerUserIdentity, }; use ruma::{ events::{ @@ -28,6 +24,7 @@ use ruma::{ }, UserId, }; +use tokio::sync::RwLock; use super::{ManualVerifyError, RequestVerificationError}; use crate::{encryption::verification::VerificationRequest, room::Joined, Client}; diff --git a/crates/matrix-sdk/src/room/common.rs b/crates/matrix-sdk/src/room/common.rs index 731b548db..ee9f33616 100644 --- a/crates/matrix-sdk/src/room/common.rs +++ b/crates/matrix-sdk/src/room/common.rs @@ -5,7 +5,6 @@ use matrix_sdk_base::{ store::StateStoreExt, StateChanges, }; -use matrix_sdk_common::locks::Mutex; #[cfg(feature = "e2e-encryption")] use ruma::events::{ room::encrypted::OriginalSyncRoomEncryptedEvent, AnySyncMessageLikeEvent, AnySyncTimelineEvent, @@ -46,6 +45,7 @@ use ruma::{ UInt, UserId, }; use serde::de::DeserializeOwned; +use tokio::sync::Mutex; use tracing::debug; #[cfg(feature = "experimental-timeline")] diff --git a/crates/matrix-sdk/src/room/joined.rs b/crates/matrix-sdk/src/room/joined.rs index 0cc5b1d82..ec1f073a5 100644 --- a/crates/matrix-sdk/src/room/joined.rs +++ b/crates/matrix-sdk/src/room/joined.rs @@ -5,8 +5,6 @@ use std::sync::Arc; use std::{borrow::Borrow, ops::Deref}; use matrix_sdk_common::instant::{Duration, Instant}; -#[cfg(feature = "e2e-encryption")] -use matrix_sdk_common::locks::Mutex; use mime::{self, Mime}; use ruma::{ api::client::{ @@ -38,6 +36,8 @@ use ruma::{ EventId, Int, MxcUri, OwnedEventId, OwnedTransactionId, TransactionId, UserId, }; use serde_json::Value; +#[cfg(feature = "e2e-encryption")] +use tokio::sync::Mutex; use tracing::{debug, instrument}; use super::Left; diff --git a/crates/matrix-sdk/src/room/timeline/builder.rs b/crates/matrix-sdk/src/room/timeline/builder.rs index de2c99c8c..30a1b8771 100644 --- a/crates/matrix-sdk/src/room/timeline/builder.rs +++ b/crates/matrix-sdk/src/room/timeline/builder.rs @@ -15,14 +15,12 @@ use std::sync::Arc; use imbl::Vector; -use matrix_sdk_base::{ - deserialized_responses::{EncryptionInfo, SyncTimelineEvent}, - locks::Mutex, -}; +use matrix_sdk_base::deserialized_responses::{EncryptionInfo, SyncTimelineEvent}; use ruma::{ events::receipt::{ReceiptThread, ReceiptType, SyncReceiptEvent}, push::Action, }; +use tokio::sync::Mutex; use tracing::error; #[cfg(feature = "e2e-encryption")] diff --git a/crates/matrix-sdk/src/room/timeline/inner.rs b/crates/matrix-sdk/src/room/timeline/inner.rs index add5def68..ba27050c9 100644 --- a/crates/matrix-sdk/src/room/timeline/inner.rs +++ b/crates/matrix-sdk/src/room/timeline/inner.rs @@ -22,10 +22,7 @@ use imbl::Vector; use indexmap::{IndexMap, IndexSet}; #[cfg(feature = "e2e-encryption")] use matrix_sdk_base::crypto::OlmMachine; -use matrix_sdk_base::{ - deserialized_responses::{EncryptionInfo, SyncTimelineEvent, TimelineEvent}, - locks::{Mutex, MutexGuard}, -}; +use matrix_sdk_base::deserialized_responses::{EncryptionInfo, SyncTimelineEvent, TimelineEvent}; #[cfg(feature = "e2e-encryption")] use ruma::RoomId; use ruma::{ @@ -41,6 +38,7 @@ use ruma::{ EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId, OwnedUserId, TransactionId, UserId, }; +use tokio::sync::{Mutex, MutexGuard}; use tracing::{debug, error, field::debug, instrument, trace, warn}; #[cfg(feature = "e2e-encryption")] use tracing::{field, info, info_span, Instrument as _}; diff --git a/crates/matrix-sdk/src/room/timeline/mod.rs b/crates/matrix-sdk/src/room/timeline/mod.rs index 8bbdbce81..60c8b86b3 100644 --- a/crates/matrix-sdk/src/room/timeline/mod.rs +++ b/crates/matrix-sdk/src/room/timeline/mod.rs @@ -21,7 +21,6 @@ use std::{pin::Pin, sync::Arc, task::Poll}; use eyeball_im::{VectorDiff, VectorSubscriber}; use futures_core::Stream; use imbl::Vector; -use matrix_sdk_base::locks::Mutex; use pin_project_lite::pin_project; use ruma::{ api::client::receipt::create_receipt::v3::ReceiptType, @@ -33,6 +32,7 @@ use ruma::{ EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, TransactionId, UserId, }; use thiserror::Error; +use tokio::sync::Mutex; use tracing::{error, instrument, warn}; use super::{Joined, Receipts}; diff --git a/crates/matrix-sdk/src/sliding_sync/mod.rs b/crates/matrix-sdk/src/sliding_sync/mod.rs index 93b411107..1fcf41199 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -558,7 +558,6 @@ use eyeball::unique::Observable; use futures_core::stream::Stream; pub use list::*; use matrix_sdk_base::sync::SyncResponse; -use matrix_sdk_common::locks::Mutex as AsyncMutex; pub use room::*; use ruma::{ api::client::{ @@ -570,7 +569,7 @@ use ruma::{ assign, OwnedRoomId, RoomId, }; use serde::{Deserialize, Serialize}; -use tokio::spawn; +use tokio::{spawn, sync::Mutex as AsyncMutex}; use tracing::{debug, error, info_span, instrument, trace, warn, Instrument, Span}; use url::Url; use uuid::Uuid;