Commit d2e183fa authored by Vincent Pelletier's avatar Vincent Pelletier

It is pointless to instantiate a lock as a local value, as function local...

It is pointless to instantiate a lock as a local value, as function local values are local to any given call, hence local to a thread.
Moreover, there is no need to lock access to a persistent object, as its access is protected by ACID.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29082 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 67f8bdca
...@@ -36,8 +36,6 @@ from Products.CMFCore.utils import getToolByName ...@@ -36,8 +36,6 @@ from Products.CMFCore.utils import getToolByName
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
from Products.ERP5 import _dtmldir from Products.ERP5 import _dtmldir
import threading
from BTrees.Length import Length from BTrees.Length import Length
class IdTool(BaseTool): class IdTool(BaseTool):
...@@ -77,12 +75,7 @@ class IdTool(BaseTool): ...@@ -77,12 +75,7 @@ class IdTool(BaseTool):
if getattr(aq_base(self), 'dict_ids', None) is None: if getattr(aq_base(self), 'dict_ids', None) is None:
self.dict_ids = PersistentMapping() self.dict_ids = PersistentMapping()
if id_group is not None and id_group!='None': if id_group is not None and id_group!='None':
l = threading.Lock() self.dict_ids[id_group] = new_id
l.acquire()
try:
self.dict_ids[id_group] = new_id
finally:
l.release()
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'generateNewId') 'generateNewId')
...@@ -98,31 +91,26 @@ class IdTool(BaseTool): ...@@ -98,31 +91,26 @@ class IdTool(BaseTool):
if id_group is not None and id_group!='None': if id_group is not None and id_group!='None':
# Getting the last id # Getting the last id
last_id = None last_id = None
l = threading.Lock() class Dummy:
l.acquire() pass
try: dummy = Dummy()
class Dummy: last_id = self.dict_ids.get(id_group, dummy)
pass if last_id is dummy:
dummy = Dummy() if default is None:
last_id = self.dict_ids.get(id_group, dummy) new_id=0
if last_id is dummy: else:
if default is None: new_id=default
new_id=0 if method is not None:
else: new_id=method(new_id)
new_id=default else:
if method is not None: # Now generate a new id
new_id=method(new_id) if method is not None:
else: new_id = method(last_id)
# Now generate a new id else:
if method is not None: new_id = last_id + 1
new_id = method(last_id)
else: # Store the new value
new_id = last_id + 1 self.dict_ids[id_group] = new_id
# Store the new value
self.dict_ids[id_group] = new_id
finally:
l.release()
return new_id return new_id
......
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