1- use parking_lot:: { ArcMutexGuard , Mutex , RawMutex } ;
1+ use parking_lot:: { ArcRwLockReadGuard , RawRwLock , RwLock } ;
22use std:: sync:: Arc ;
33
44use re_chunk_store:: ChunkStoreEvent ;
@@ -12,25 +12,25 @@ use re_viewer_context::{Cache, CacheMemoryReport};
1212#[ derive( Default ) ]
1313pub struct TransformDatabaseStoreCache {
1414 initialized : bool ,
15- transform_cache : Arc < Mutex < TransformResolutionCache > > ,
15+ transform_cache : Arc < RwLock < TransformResolutionCache > > ,
1616}
1717
1818impl 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
0 commit comments