66ChangeSet applications and flag change notifications.
77"""
88
9- import threading
109from collections import defaultdict
1110from typing import Any , Callable , Dict , List , Optional , Set
1211
@@ -194,7 +193,7 @@ def __init__(
194193 self ._selector = Selector .no_selector ()
195194
196195 # Thread synchronization
197- self ._lock = threading . RLock ()
196+ self ._lock = ReadWriteLock ()
198197
199198 def with_persistence (
200199 self ,
@@ -213,7 +212,7 @@ def with_persistence(
213212 Returns:
214213 Self for method chaining
215214 """
216- with self ._lock :
215+ with self ._lock . write_lock () :
217216 self ._persistent_store = persistent_store
218217 self ._persistent_store_writable = writable
219218 self ._persistent_store_status_provider = status_provider
@@ -225,12 +224,12 @@ def with_persistence(
225224
226225 def selector (self ) -> Selector :
227226 """Returns the current selector."""
228- with self ._lock :
227+ with self ._lock . read_lock () :
229228 return self ._selector
230229
231230 def close (self ) -> Optional [Exception ]:
232231 """Close the store and any persistent store if configured."""
233- with self ._lock :
232+ with self ._lock . write_lock () :
234233 if self ._persistent_store is not None :
235234 try :
236235 # Most FeatureStore implementations don't have close methods
@@ -251,7 +250,7 @@ def apply(self, change_set: ChangeSet, persist: bool) -> None:
251250 """
252251 collections = self ._changes_to_store_data (change_set .changes )
253252
254- with self ._lock :
253+ with self ._lock . write_lock () :
255254 try :
256255 if change_set .intent_code == IntentCode .TRANSFER_FULL :
257256 self ._set_basis (collections , change_set .selector , persist )
@@ -443,7 +442,7 @@ def __mapping(data: Dict[str, ModelEntity]) -> Dict[str, Dict[str, Any]]:
443442
444443 return __mapping
445444
446- with self ._lock :
445+ with self ._lock . write_lock () :
447446 if self ._should_persist ():
448447 try :
449448 # Get all data from memory store and write to persistent store
@@ -457,7 +456,7 @@ def __mapping(data: Dict[str, ModelEntity]) -> Dict[str, Dict[str, Any]]:
457456
458457 def get_active_store (self ) -> ReadOnlyStore :
459458 """Get the currently active store for reading data."""
460- with self ._lock :
459+ with self ._lock . read_lock () :
461460 return self ._active_store
462461
463462 def is_initialized (self ) -> bool :
@@ -466,5 +465,5 @@ def is_initialized(self) -> bool:
466465
467466 def get_data_store_status_provider (self ) -> Optional [DataStoreStatusProvider ]:
468467 """Get the data store status provider for the persistent store, if configured."""
469- with self ._lock :
468+ with self ._lock . read_lock () :
470469 return self ._persistent_store_status_provider
0 commit comments