From 5fe5cfd85f7916ffbc276e090941dc00f2bbf37d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 10 Sep 2025 14:51:37 +0200 Subject: [PATCH] refactor(common): Rename `CrossProcessStoreLock*` to `CrossProcessLock*`. This patch renames `CrossProcessStoreLock` and `CrossProcessStoreLockGuard` to `CrossProcessLock` and `CrossProcessLockGuard`. --- .../src/event_cache/store/mod.rs | 12 +++---- crates/matrix-sdk-base/src/media/store/mod.rs | 12 +++---- crates/matrix-sdk-base/src/store/mod.rs | 2 +- crates/matrix-sdk-common/src/store_locks.rs | 36 +++++++++---------- .../src/store/crypto_store_wrapper.rs | 8 ++--- crates/matrix-sdk-crypto/src/store/mod.rs | 6 ++-- .../src/authentication/oauth/cross_process.rs | 10 +++--- crates/matrix-sdk/src/client/builder/mod.rs | 2 +- crates/matrix-sdk/src/client/mod.rs | 13 ++++--- crates/matrix-sdk/src/encryption/mod.rs | 4 +-- 10 files changed, 50 insertions(+), 55 deletions(-) diff --git a/crates/matrix-sdk-base/src/event_cache/store/mod.rs b/crates/matrix-sdk-base/src/event_cache/store/mod.rs index 7d8ce765c..2a099b078 100644 --- a/crates/matrix-sdk-base/src/event_cache/store/mod.rs +++ b/crates/matrix-sdk-base/src/event_cache/store/mod.rs @@ -28,7 +28,7 @@ mod memory_store; mod traits; use matrix_sdk_common::store_locks::{ - BackingStore, CrossProcessStoreLock, CrossProcessStoreLockGuard, LockStoreError, + BackingStore, CrossProcessLock, CrossProcessLockGuard, LockStoreError, }; pub use matrix_sdk_store_encryption::Error as StoreEncryptionError; use ruma::{ @@ -49,7 +49,7 @@ pub use self::{ #[derive(Clone)] pub struct EventCacheStoreLock { /// The inner cross process lock that is used to lock the `EventCacheStore`. - cross_process_lock: Arc>, + cross_process_lock: Arc>, /// The store itself. /// @@ -68,7 +68,7 @@ impl EventCacheStoreLock { /// Create a new lock around the [`EventCacheStore`]. /// /// The `holder` argument represents the holder inside the - /// [`CrossProcessStoreLock::new`]. + /// [`CrossProcessLock::new`]. pub fn new(store: S, holder: String) -> Self where S: IntoEventCacheStore, @@ -76,7 +76,7 @@ impl EventCacheStoreLock { let store = store.into_event_cache_store(); Self { - cross_process_lock: Arc::new(CrossProcessStoreLock::new( + cross_process_lock: Arc::new(CrossProcessLock::new( LockableEventCacheStore(store.clone()), "default".to_owned(), holder, @@ -85,7 +85,7 @@ impl EventCacheStoreLock { } } - /// Acquire a spin lock (see [`CrossProcessStoreLock::spin_lock`]). + /// Acquire a spin lock (see [`CrossProcessLock::spin_lock`]). pub async fn lock(&self) -> Result, LockStoreError> { let cross_process_lock_guard = self.cross_process_lock.spin_lock(None).await?; @@ -99,7 +99,7 @@ impl EventCacheStoreLock { pub struct EventCacheStoreLockGuard<'a> { /// The cross process lock guard. #[allow(unused)] - cross_process_lock_guard: CrossProcessStoreLockGuard, + cross_process_lock_guard: CrossProcessLockGuard, /// A reference to the store. store: &'a DynEventCacheStore, diff --git a/crates/matrix-sdk-base/src/media/store/mod.rs b/crates/matrix-sdk-base/src/media/store/mod.rs index 973b5269e..d6edabd11 100644 --- a/crates/matrix-sdk-base/src/media/store/mod.rs +++ b/crates/matrix-sdk-base/src/media/store/mod.rs @@ -32,7 +32,7 @@ use std::fmt; use std::{ops::Deref, sync::Arc}; use matrix_sdk_common::store_locks::{ - BackingStore, CrossProcessStoreLock, CrossProcessStoreLockGuard, LockStoreError, + BackingStore, CrossProcessLock, CrossProcessLockGuard, LockStoreError, }; use matrix_sdk_store_encryption::Error as StoreEncryptionError; pub use traits::{DynMediaStore, IntoMediaStore, MediaStore, MediaStoreInner}; @@ -88,7 +88,7 @@ pub type Result = std::result::Result; #[derive(Clone)] pub struct MediaStoreLock { /// The inner cross process lock that is used to lock the `MediaStore`. - cross_process_lock: Arc>, + cross_process_lock: Arc>, /// The store itself. /// @@ -107,7 +107,7 @@ impl MediaStoreLock { /// Create a new lock around the [`MediaStore`]. /// /// The `holder` argument represents the holder inside the - /// [`CrossProcessStoreLock::new`]. + /// [`CrossProcessLock::new`]. pub fn new(store: S, holder: String) -> Self where S: IntoMediaStore, @@ -115,7 +115,7 @@ impl MediaStoreLock { let store = store.into_media_store(); Self { - cross_process_lock: Arc::new(CrossProcessStoreLock::new( + cross_process_lock: Arc::new(CrossProcessLock::new( LockableMediaStore(store.clone()), "default".to_owned(), holder, @@ -124,7 +124,7 @@ impl MediaStoreLock { } } - /// Acquire a spin lock (see [`CrossProcessStoreLock::spin_lock`]). + /// Acquire a spin lock (see [`CrossProcessLock::spin_lock`]). pub async fn lock(&self) -> Result, LockStoreError> { let cross_process_lock_guard = self.cross_process_lock.spin_lock(None).await?; @@ -138,7 +138,7 @@ impl MediaStoreLock { pub struct MediaStoreLockGuard<'a> { /// The cross process lock guard. #[allow(unused)] - cross_process_lock_guard: CrossProcessStoreLockGuard, + cross_process_lock_guard: CrossProcessLockGuard, /// A reference to the store. store: &'a DynMediaStore, diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index 93cd96fff..541e896c1 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -791,7 +791,7 @@ impl StoreConfig { /// Create a new default `StoreConfig`. /// /// To learn more about `cross_process_store_locks_holder_name`, please read - /// [`CrossProcessStoreLock::new`](matrix_sdk_common::store_locks::CrossProcessStoreLock::new). + /// [`CrossProcessLock::new`](matrix_sdk_common::store_locks::CrossProcessLock::new). #[must_use] pub fn new(cross_process_store_locks_holder_name: String) -> Self { Self { diff --git a/crates/matrix-sdk-common/src/store_locks.rs b/crates/matrix-sdk-common/src/store_locks.rs index 9d070d4ba..144dd8f82 100644 --- a/crates/matrix-sdk-common/src/store_locks.rs +++ b/crates/matrix-sdk-common/src/store_locks.rs @@ -82,16 +82,16 @@ enum WaitingTime { Stop, } -/// A guard on the store lock. +/// A guard of a cross-process lock. /// /// The lock will be automatically released a short period of time after all the /// guards have dropped. #[derive(Debug)] -pub struct CrossProcessStoreLockGuard { +pub struct CrossProcessLockGuard { num_holders: Arc, } -impl Drop for CrossProcessStoreLockGuard { +impl Drop for CrossProcessLockGuard { fn drop(&mut self) { self.num_holders.fetch_sub(1, atomic::Ordering::SeqCst); } @@ -101,7 +101,7 @@ impl Drop for CrossProcessStoreLockGuard { /// /// See the doc-comment of this module for more information. #[derive(Clone, Debug)] -pub struct CrossProcessStoreLock { +pub struct CrossProcessLock { /// The store we're using to lock. store: S, @@ -149,7 +149,7 @@ const INITIAL_BACKOFF_MS: u32 = 10; /// we'll wait for the lock, *between two attempts*. pub const MAX_BACKOFF_MS: u32 = 1000; -impl CrossProcessStoreLock { +impl CrossProcessLock { /// Create a new store-based lock implemented as a value in the store. /// /// # Parameters @@ -170,9 +170,7 @@ impl CrossProcessStoreLock< /// Try to lock once, returns whether the lock was obtained or not. #[instrument(skip(self), fields(?self.lock_key, ?self.lock_holder))] - pub async fn try_lock_once( - &self, - ) -> Result, LockStoreError> { + pub async fn try_lock_once(&self) -> Result, LockStoreError> { // Hold onto the locking attempt mutex for the entire lifetime of this // function, to avoid multiple reentrant calls. let mut _attempt = self.locking_attempt.lock().await; @@ -186,7 +184,7 @@ impl CrossProcessStoreLock< // taken by at least one thread. trace!("We already had the lock, incrementing holder count"); self.num_holders.fetch_add(1, atomic::Ordering::SeqCst); - let guard = CrossProcessStoreLockGuard { num_holders: self.num_holders.clone() }; + let guard = CrossProcessLockGuard { num_holders: self.num_holders.clone() }; return Ok(Some(guard)); } @@ -266,7 +264,7 @@ impl CrossProcessStoreLock< self.num_holders.fetch_add(1, atomic::Ordering::SeqCst); - let guard = CrossProcessStoreLockGuard { num_holders: self.num_holders.clone() }; + let guard = CrossProcessLockGuard { num_holders: self.num_holders.clone() }; Ok(Some(guard)) } @@ -282,7 +280,7 @@ impl CrossProcessStoreLock< pub async fn spin_lock( &self, max_backoff: Option, - ) -> Result { + ) -> Result { let max_backoff = max_backoff.unwrap_or(MAX_BACKOFF_MS); // Note: reads/writes to the backoff are racy across threads in theory, but the @@ -359,7 +357,7 @@ mod tests { }; use super::{ - BackingStore, CrossProcessStoreLock, CrossProcessStoreLockGuard, EXTEND_LEASE_EVERY_MS, + BackingStore, CrossProcessLock, CrossProcessLockGuard, EXTEND_LEASE_EVERY_MS, LockStoreError, memory_store_helper::try_take_leased_lock, }; @@ -391,7 +389,7 @@ mod tests { } } - async fn release_lock(guard: Option) { + async fn release_lock(guard: Option) { drop(guard); sleep(Duration::from_millis(EXTEND_LEASE_EVERY_MS)).await; } @@ -401,7 +399,7 @@ mod tests { #[async_test] async fn test_simple_lock_unlock() -> TestResult { let store = TestStore::default(); - let lock = CrossProcessStoreLock::new(store, "key".to_owned(), "first".to_owned()); + let lock = CrossProcessLock::new(store, "key".to_owned(), "first".to_owned()); // The lock plain works when used with a single holder. let acquired = lock.try_lock_once().await?; @@ -425,7 +423,7 @@ mod tests { #[async_test] async fn test_self_recovery() -> TestResult { let store = TestStore::default(); - let lock = CrossProcessStoreLock::new(store.clone(), "key".to_owned(), "first".to_owned()); + let lock = CrossProcessLock::new(store.clone(), "key".to_owned(), "first".to_owned()); // When a lock is acquired... let acquired = lock.try_lock_once().await?; @@ -436,7 +434,7 @@ mod tests { drop(lock); // And when rematerializing the lock with the same key/value... - let lock = CrossProcessStoreLock::new(store.clone(), "key".to_owned(), "first".to_owned()); + let lock = CrossProcessLock::new(store.clone(), "key".to_owned(), "first".to_owned()); // We still got it. let acquired = lock.try_lock_once().await?; @@ -449,7 +447,7 @@ mod tests { #[async_test] async fn test_multiple_holders_same_process() -> TestResult { let store = TestStore::default(); - let lock = CrossProcessStoreLock::new(store, "key".to_owned(), "first".to_owned()); + let lock = CrossProcessLock::new(store, "key".to_owned(), "first".to_owned()); // Taking the lock twice... let acquired = lock.try_lock_once().await?; @@ -473,8 +471,8 @@ mod tests { #[async_test] async fn test_multiple_processes() -> TestResult { let store = TestStore::default(); - let lock1 = CrossProcessStoreLock::new(store.clone(), "key".to_owned(), "first".to_owned()); - let lock2 = CrossProcessStoreLock::new(store, "key".to_owned(), "second".to_owned()); + let lock1 = CrossProcessLock::new(store.clone(), "key".to_owned(), "first".to_owned()); + let lock2 = CrossProcessLock::new(store, "key".to_owned(), "second".to_owned()); // When the first process takes the lock... let acquired1 = lock1.try_lock_once().await?; diff --git a/crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs b/crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs index 071f35626..678fcf677 100644 --- a/crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs +++ b/crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs @@ -2,7 +2,7 @@ use std::{future, ops::Deref, sync::Arc}; use futures_core::Stream; use futures_util::StreamExt; -use matrix_sdk_common::store_locks::CrossProcessStoreLock; +use matrix_sdk_common::store_locks::CrossProcessLock; use ruma::{DeviceId, OwnedDeviceId, OwnedUserId, UserId}; use tokio::sync::{broadcast, Mutex}; use tokio_stream::wrappers::{errors::BroadcastStreamRecvError, BroadcastStream}; @@ -390,14 +390,14 @@ impl CryptoStoreWrapper { }) } - /// Creates a `CrossProcessStoreLock` for this store, that will contain the + /// Creates a [`CrossProcessLock`] for this store, that will contain the /// given key and value when hold. pub(crate) fn create_store_lock( &self, lock_key: String, lock_value: String, - ) -> CrossProcessStoreLock { - CrossProcessStoreLock::new(LockableCryptoStore(self.store.clone()), lock_key, lock_value) + ) -> CrossProcessLock { + CrossProcessLock::new(LockableCryptoStore(self.store.clone()), lock_key, lock_value) } } diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index b1ca5c834..e3ccc36d6 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -99,7 +99,7 @@ pub mod integration_tests; pub(crate) use crypto_store_wrapper::CryptoStoreWrapper; pub use error::{CryptoStoreError, Result}; use matrix_sdk_common::{ - deserialized_responses::WithheldCode, store_locks::CrossProcessStoreLock, timeout::timeout, + deserialized_responses::WithheldCode, store_locks::CrossProcessLock, timeout::timeout, }; pub use memorystore::MemoryStore; pub use traits::{CryptoStore, DynCryptoStore, IntoCryptoStore}; @@ -1261,13 +1261,13 @@ impl Store { self.inner.store.identities_stream().map(|(_, identities, devices)| (identities, devices)) } - /// Creates a `CrossProcessStoreLock` for this store, that will contain the + /// Creates a [`CrossProcessLock`] for this store, that will contain the /// given key and value when hold. pub fn create_store_lock( &self, lock_key: String, lock_value: String, - ) -> CrossProcessStoreLock { + ) -> CrossProcessLock { self.inner.store.create_store_lock(lock_key, lock_value) } diff --git a/crates/matrix-sdk/src/authentication/oauth/cross_process.rs b/crates/matrix-sdk/src/authentication/oauth/cross_process.rs index d416b1c8c..bf8f0df5c 100644 --- a/crates/matrix-sdk/src/authentication/oauth/cross_process.rs +++ b/crates/matrix-sdk/src/authentication/oauth/cross_process.rs @@ -5,9 +5,7 @@ use matrix_sdk_base::crypto::{ store::{LockableCryptoStore, Store}, CryptoStoreError, }; -use matrix_sdk_common::store_locks::{ - CrossProcessStoreLock, CrossProcessStoreLockGuard, LockStoreError, -}; +use matrix_sdk_common::store_locks::{CrossProcessLock, CrossProcessLockGuard, LockStoreError}; use sha2::{Digest as _, Sha256}; use thiserror::Error; use tokio::sync::{Mutex, OwnedMutexGuard}; @@ -61,13 +59,13 @@ fn compute_session_hash(tokens: &SessionTokens) -> SessionHash { #[derive(Clone)] pub(super) struct CrossProcessRefreshManager { store: Store, - store_lock: CrossProcessStoreLock, + store_lock: CrossProcessLock, known_session_hash: Arc>>, } impl CrossProcessRefreshManager { /// Create a new `CrossProcessRefreshManager`. - pub fn new(store: Store, lock: CrossProcessStoreLock) -> Self { + pub fn new(store: Store, lock: CrossProcessLock) -> Self { Self { store, store_lock: lock, known_session_hash: Arc::new(Mutex::new(None)) } } @@ -134,7 +132,7 @@ pub(super) struct CrossProcessRefreshLockGuard { hash_guard: OwnedMutexGuard>, /// Cross-process lock being hold. - _store_guard: CrossProcessStoreLockGuard, + _store_guard: CrossProcessLockGuard, /// Reference to the underlying store, for storing the hash of the latest /// known session (as a custom value). diff --git a/crates/matrix-sdk/src/client/builder/mod.rs b/crates/matrix-sdk/src/client/builder/mod.rs index 409b5f5c5..26943aa44 100644 --- a/crates/matrix-sdk/src/client/builder/mod.rs +++ b/crates/matrix-sdk/src/client/builder/mod.rs @@ -482,7 +482,7 @@ impl ClientBuilder { /// Set the cross-process store locks holder name. /// /// The SDK provides cross-process store locks (see - /// [`matrix_sdk_common::store_locks::CrossProcessStoreLock`]). The + /// [`matrix_sdk_common::store_locks::CrossProcessLock`]). The /// `holder_name` will be the value used for all cross-process store locks /// used by the `Client` being built. /// diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 74a6ab01f..01d2d0a67 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -111,7 +111,7 @@ use crate::{ #[cfg(feature = "e2e-encryption")] use crate::{ encryption::{Encryption, EncryptionData, EncryptionSettings, VerificationState}, - store_locks::CrossProcessStoreLock, + store_locks::CrossProcessLock, }; mod builder; @@ -235,8 +235,7 @@ pub(crate) struct ClientLocks { pub(crate) read_receipt_deduplicated_handler: DeduplicatingHandler<(String, OwnedEventId)>, #[cfg(feature = "e2e-encryption")] - pub(crate) cross_process_crypto_store_lock: - OnceCell>, + pub(crate) cross_process_crypto_store_lock: OnceCell>, /// Latest "generation" of data known by the crypto store. /// @@ -302,7 +301,7 @@ pub(crate) struct ClientInner { /// The cross-process store locks holder name. /// /// The SDK provides cross-process store locks (see - /// [`matrix_sdk_common::store_locks::CrossProcessStoreLock`]). The + /// [`matrix_sdk_common::store_locks::CrossProcessLock`]). The /// `holder_name` is the value used for all cross-process store locks /// used by this `Client`. /// @@ -520,7 +519,7 @@ impl Client { /// The cross-process store locks holder name. /// /// The SDK provides cross-process store locks (see - /// [`matrix_sdk_common::store_locks::CrossProcessStoreLock`]). The + /// [`matrix_sdk_common::store_locks::CrossProcessLock`]). The /// `holder_name` is the value used for all cross-process store locks /// used by this `Client`. pub fn cross_process_store_locks_holder_name(&self) -> &str { @@ -2765,10 +2764,10 @@ impl Client { /// Create a new specialized `Client` that can process notifications. /// - /// See [`CrossProcessStoreLock::new`] to learn more about + /// See [`CrossProcessLock::new`] to learn more about /// `cross_process_store_locks_holder_name`. /// - /// [`CrossProcessStoreLock::new`]: matrix_sdk_common::store_locks::CrossProcessStoreLock::new + /// [`CrossProcessLock::new`]: matrix_sdk_common::store_locks::CrossProcessLock::new pub async fn notification_client( &self, cross_process_store_locks_holder_name: String, diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index e832f919d..38034cf22 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -92,7 +92,7 @@ use crate::{ attachment::Thumbnail, client::{ClientInner, WeakClient}, error::HttpResult, - store_locks::CrossProcessStoreLockGuard, + store_locks::CrossProcessLockGuard, Client, Error, HttpError, Result, Room, RumaApiError, TransmissionProgress, }; @@ -238,7 +238,7 @@ pub enum VerificationState { /// Wraps together a `CrossProcessLockStoreGuard` and a generation number. #[derive(Debug)] pub struct CrossProcessLockStoreGuardWithGeneration { - _guard: CrossProcessStoreLockGuard, + _guard: CrossProcessLockGuard, generation: u64, }