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,11 +61,13 @@ class MVCCAdapter(Base): ...@@ -61,11 +61,13 @@ 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)
with self._lock:
self._instances.add(instance) self._instances.add(instance)
return instance return instance
...@@ -76,6 +78,7 @@ class MVCCAdapter(Base): ...@@ -76,6 +78,7 @@ class MVCCAdapter(Base):
return UndoAdapterInstance(self) return UndoAdapterInstance(self)
def _release(self, instance): def _release(self, instance):
with self._lock:
self._instances.remove(instance) self._instances.remove(instance)
closed = False closed = False
...@@ -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):
with self._lock:
for instance in self._instances: for instance in self._instances:
instance._invalidateCache() instance._invalidateCache()
def invalidate(self, transaction_id, oids, version=''): def invalidate(self, transaction_id, oids, version=''):
with self._lock:
for instance in self._instances: for instance in self._instances:
instance._invalidate(oids) instance._invalidate(oids)
references = serialize.referencesf
transform_record_data = untransform_record_data = lambda self, data: data
def _invalidate_finish(self, oids, committing_instance): def _invalidate_finish(self, oids, committing_instance):
with self._lock:
for instance in self._instances: for instance in self._instances:
if instance is not committing_instance: if instance is not committing_instance:
instance._invalidate(oids) instance._invalidate(oids)
references = serialize.referencesf
transform_record_data = untransform_record_data = lambda self, data: data
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