Skip to content

Commit f3b9a01

Browse files
bnjbvrHywan
authored andcommitted
refactor(event cache): rename the read_lock_acquisition mutex
1 parent 2fb5a32 commit f3b9a01

File tree

1 file changed

+7
-4
lines changed
  • crates/matrix-sdk/src/event_cache/room

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,12 @@ mod private {
723723
/// The per-thread lock around the real state.
724724
locked_state: RwLock<RoomEventCacheState>,
725725

726+
/// A lock taken to avoid multiple attempts to upgrade from a read lock
727+
/// to a write lock.
728+
///
726729
/// Please see inline comment of [`Self::read`] to understand why it
727730
/// exists.
728-
read_lock_acquisition: Mutex<()>,
731+
state_lock_upgrade_mutex: Mutex<()>,
729732
}
730733

731734
struct RoomEventCacheState {
@@ -885,7 +888,7 @@ mod private {
885888
waited_for_initial_prev_token,
886889
subscriber_count: Default::default(),
887890
}),
888-
read_lock_acquisition: Mutex::new(()),
891+
state_lock_upgrade_mutex: Mutex::new(()),
889892
})
890893
}
891894

@@ -945,7 +948,7 @@ mod private {
945948
//
946949
// [^1]: https://docs.rs/lock_api/0.4.14/lock_api/struct.RwLock.html#method.upgradable_read
947950
// [^2]: https://docs.rs/async-lock/3.4.1/async_lock/struct.RwLock.html#method.upgradable_read
948-
let _one_reader_guard = self.read_lock_acquisition.lock().await;
951+
let _state_lock_upgrade_guard = self.state_lock_upgrade_mutex.lock().await;
949952

950953
// Obtain a read lock.
951954
let state_guard = self.locked_state.read().await;
@@ -957,7 +960,7 @@ mod private {
957960
EventCacheStoreLockState::Dirty(store_guard) => {
958961
// Drop the read lock, and take a write lock to modify the state.
959962
// This is safe because only one reader at a time (see
960-
// `Self::read_lock_acquisition`) is allowed.
963+
// `Self::state_lock_upgrade_mutex`) is allowed.
961964
drop(state_guard);
962965
let state_guard = self.locked_state.write().await;
963966

0 commit comments

Comments
 (0)