Commit 1731c16f authored by Jim Fulton's avatar Jim Fulton

Added a lock on the adapter

To prevent modifying the set of instances while iterating over them.
parent 29091374
...@@ -61,12 +61,14 @@ class MVCCAdapter(Base): ...@@ -61,12 +61,14 @@ class MVCCAdapter(Base):
def __init__(self, storage): def __init__(self, storage):
Base.__init__(self, storage) Base.__init__(self, storage)
self._instances = set() self._instances = set()
self._lock = threading.Lock()
if hasattr(storage, 'registerDB'): if hasattr(storage, 'registerDB'):
storage.registerDB(self) storage.registerDB(self)
def new_instance(self): def new_instance(self):
instance = MVCCAdapterInstance(self) instance = MVCCAdapterInstance(self)
self._instances.add(instance) with self._lock:
self._instances.add(instance)
return instance return instance
def before_instance(self, before=None): def before_instance(self, before=None):
...@@ -76,7 +78,8 @@ class MVCCAdapter(Base): ...@@ -76,7 +78,8 @@ class MVCCAdapter(Base):
return UndoAdapterInstance(self) return UndoAdapterInstance(self)
def _release(self, instance): def _release(self, instance):
self._instances.remove(instance) with self._lock:
self._instances.remove(instance)
closed = False closed = False
def close(self): def close(self):
...@@ -87,21 +90,24 @@ class MVCCAdapter(Base): ...@@ -87,21 +90,24 @@ class MVCCAdapter(Base):
del self._storage del self._storage
def invalidateCache(self): def invalidateCache(self):
for instance in self._instances: with self._lock:
instance._invalidateCache() for instance in self._instances:
instance._invalidateCache()
def invalidate(self, transaction_id, oids, version=''): def invalidate(self, transaction_id, oids, version=''):
for instance in self._instances: with self._lock:
instance._invalidate(oids) for instance in self._instances:
instance._invalidate(oids)
def _invalidate_finish(self, oids, committing_instance):
with self._lock:
for instance in self._instances:
if instance is not committing_instance:
instance._invalidate(oids)
references = serialize.referencesf references = serialize.referencesf
transform_record_data = untransform_record_data = lambda self, data: data transform_record_data = untransform_record_data = lambda self, data: data
def _invalidate_finish(self, oids, committing_instance):
for instance in self._instances:
if instance is not committing_instance:
instance._invalidate(oids)
def pack(self, pack_time, referencesf): def pack(self, pack_time, referencesf):
return self._storage.pack(pack_time, referencesf) return self._storage.pack(pack_time, referencesf)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment