Skip to content

Commit 3ebcafc

Browse files
committed
only read lock transform cache
1 parent 4abee78 commit 3ebcafc

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

crates/viewer/re_view_spatial/src/caches/transform_database_store.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use parking_lot::{ArcMutexGuard, Mutex, RawMutex};
1+
use parking_lot::{ArcRwLockReadGuard, RawRwLock, RwLock};
22
use std::sync::Arc;
33

44
use re_chunk_store::ChunkStoreEvent;
@@ -12,25 +12,25 @@ use re_viewer_context::{Cache, CacheMemoryReport};
1212
#[derive(Default)]
1313
pub struct TransformDatabaseStoreCache {
1414
initialized: bool,
15-
transform_cache: Arc<Mutex<TransformResolutionCache>>,
15+
transform_cache: Arc<RwLock<TransformResolutionCache>>,
1616
}
1717

1818
impl TransformDatabaseStoreCache {
1919
/// Gets access to the transform cache.
2020
///
2121
/// If the cache was newly added, will make sure that all existing chunks in the entity db are processed.
22-
pub fn lock_transform_cache(
22+
pub fn read_lock_transform_cache(
2323
&mut self,
2424
entity_db: &EntityDb,
25-
) -> ArcMutexGuard<RawMutex, TransformResolutionCache> {
25+
) -> ArcRwLockReadGuard<RawRwLock, TransformResolutionCache> {
2626
if !self.initialized {
27-
self.initialized = true;
27+
self.initialized = true; // There can't be a race here since we have `&mut self``.
2828
self.transform_cache
29-
.lock()
29+
.write()
3030
.add_chunks(entity_db.storage_engine().store().iter_chunks());
3131
}
3232

33-
self.transform_cache.lock_arc()
33+
self.transform_cache.read_arc()
3434
}
3535
}
3636

@@ -57,12 +57,12 @@ impl Cache for TransformDatabaseStoreCache {
5757
re_tracing::profile_function!();
5858

5959
debug_assert!(
60-
self.transform_cache.try_lock().is_some(),
60+
self.transform_cache.try_write().is_some(),
6161
"Transform cache is still locked on processing store events. This should never happen."
6262
);
6363

6464
self.transform_cache
65-
.lock()
65+
.write()
6666
.process_store_events(events.iter().copied());
6767
}
6868

crates/viewer/re_view_spatial/src/contexts/transform_tree_context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ impl ViewContextSystem for TransformTreeContext {
152152
ctx: &re_viewer_context::ViewerContext<'_>,
153153
) -> ViewContextSystemOncePerFrameResult {
154154
let caches = ctx.store_context.caches;
155-
let transform_cache = caches
156-
.entry(|c: &mut TransformDatabaseStoreCache| c.lock_transform_cache(ctx.recording()));
155+
let transform_cache = caches.entry(|c: &mut TransformDatabaseStoreCache| {
156+
c.read_lock_transform_cache(ctx.recording())
157+
});
157158

158159
let transform_forest =
159160
re_tf::TransformForest::new(ctx.recording(), &transform_cache, &ctx.current_query());
@@ -218,10 +219,9 @@ impl ViewContextSystem for TransformTreeContext {
218219
self.transform_infos = {
219220
re_tracing::profile_scope!("transform info lookup");
220221

221-
// TODO: bad locking.
222222
let caches = ctx.viewer_ctx.store_context.caches;
223223
let transform_cache = caches.entry(|c: &mut TransformDatabaseStoreCache| {
224-
c.lock_transform_cache(ctx.recording())
224+
c.read_lock_transform_cache(ctx.recording())
225225
});
226226
let transforms = transform_cache.transforms_for_timeline(query.timeline);
227227

0 commit comments

Comments
 (0)