Skip to content

Commit 877d665

Browse files
committed
refactor: Rename EventCacheStoreLock::lock to lock_unchecked.
We are about to introduce a lock which checks if it's been poisoned. To not break the current API semantics, `lock` is renamed `lock_unchecked` if poisoning isn't check/doesn't raise an error.
1 parent 3d228bd commit 877d665

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

crates/matrix-sdk-base/src/event_cache/store/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ impl EventCacheStoreLock {
8080
}
8181

8282
/// Acquire a spin lock (see [`CrossProcessStoreLock::spin_lock`]).
83-
pub async fn lock(&self) -> Result<EventCacheStoreLockGuard<'_>, LockStoreError> {
83+
///
84+
/// It doesn't check whether the lock has been poisoned or not.
85+
/// A lock has been poisoned if it's been acquired from another holder.
86+
pub async fn lock_unchecked(&self) -> Result<EventCacheStoreLockGuard<'_>, LockStoreError> {
8487
let cross_process_lock_guard = self.cross_process_lock.spin_lock(None).await?;
8588

8689
Ok(EventCacheStoreLockGuard { cross_process_lock_guard, store: self.store.deref() })

crates/matrix-sdk/src/media.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,13 @@ impl Media {
393393
) -> Result<Vec<u8>> {
394394
// Read from the cache.
395395
if use_cache {
396-
if let Some(content) =
397-
self.client.event_cache_store().lock().await?.get_media_content(request).await?
396+
if let Some(content) = self
397+
.client
398+
.event_cache_store()
399+
.lock_unchecked()
400+
.await?
401+
.get_media_content(request)
402+
.await?
398403
{
399404
return Ok(content);
400405
}
@@ -497,7 +502,7 @@ impl Media {
497502
if use_cache {
498503
self.client
499504
.event_cache_store()
500-
.lock()
505+
.lock_unchecked()
501506
.await?
502507
.add_media_content(request, content.clone())
503508
.await?;
@@ -512,7 +517,13 @@ impl Media {
512517
///
513518
/// * `request` - The `MediaRequest` of the content.
514519
pub async fn remove_media_content(&self, request: &MediaRequestParameters) -> Result<()> {
515-
Ok(self.client.event_cache_store().lock().await?.remove_media_content(request).await?)
520+
Ok(self
521+
.client
522+
.event_cache_store()
523+
.lock_unchecked()
524+
.await?
525+
.remove_media_content(request)
526+
.await?)
516527
}
517528

518529
/// Delete all the media content corresponding to the given
@@ -522,7 +533,13 @@ impl Media {
522533
///
523534
/// * `uri` - The `MxcUri` of the files.
524535
pub async fn remove_media_content_for_uri(&self, uri: &MxcUri) -> Result<()> {
525-
Ok(self.client.event_cache_store().lock().await?.remove_media_content_for_uri(uri).await?)
536+
Ok(self
537+
.client
538+
.event_cache_store()
539+
.lock_unchecked()
540+
.await?
541+
.remove_media_content_for_uri(uri)
542+
.await?)
526543
}
527544

528545
/// Get the file of the given media event content.

crates/matrix-sdk/src/room/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ impl Room {
19881988
.await?;
19891989

19901990
if store_in_cache {
1991-
let cache_store_lock_guard = self.client.event_cache_store().lock().await?;
1991+
let cache_store_lock_guard = self.client.event_cache_store().lock_unchecked().await?;
19921992

19931993
// A failure to cache shouldn't prevent the whole upload from finishing
19941994
// properly, so only log errors during caching.

crates/matrix-sdk/src/send_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ impl RoomSendQueue {
706706
let data = room
707707
.client()
708708
.event_cache_store()
709-
.lock()
709+
.lock_unchecked()
710710
.await?
711711
.get_media_content(&cache_key)
712712
.await?

crates/matrix-sdk/src/send_queue/upload.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl RoomSendQueue {
167167
let client = room.client();
168168
let cache_store = client
169169
.event_cache_store()
170-
.lock()
170+
.lock_unchecked()
171171
.await
172172
.map_err(RoomSendQueueStorageError::LockError)?;
173173

@@ -301,7 +301,7 @@ impl QueueStorage {
301301

302302
let cache_store = client
303303
.event_cache_store()
304-
.lock()
304+
.lock_unchecked()
305305
.await
306306
.map_err(RoomSendQueueStorageError::LockError)?;
307307

@@ -530,7 +530,7 @@ impl QueueStorage {
530530
// At this point, all the requests and dependent requests have been cleaned up.
531531
// Perform the final step: empty the cache from the local items.
532532
{
533-
let event_cache = client.event_cache_store().lock().await?;
533+
let event_cache = client.event_cache_store().lock_unchecked().await?;
534534
event_cache
535535
.remove_media_content_for_uri(&make_local_uri(&handles.upload_file_txn))
536536
.await?;

0 commit comments

Comments
 (0)