Commit 19e6cc3e authored by Vincent Pelletier's avatar Vincent Pelletier

Get rid of global_activity_buffer_lock.

parent 7daaf0a5
...@@ -32,6 +32,7 @@ import threading ...@@ -32,6 +32,7 @@ import threading
import sys import sys
from types import StringType from types import StringType
import re import re
from collections import defaultdict
from cPickle import dumps, loads from cPickle import dumps, loads
from Products.CMFCore import permissions as CMFCorePermissions from Products.CMFCore import permissions as CMFCorePermissions
from Products.ERP5Type.Core.Folder import Folder from Products.ERP5Type.Core.Folder import Folder
...@@ -140,9 +141,8 @@ def activity_timing_method(method, args, kw): ...@@ -140,9 +141,8 @@ def activity_timing_method(method, args, kw):
# Here go ActivityBuffer instances # Here go ActivityBuffer instances
# Structure: # Structure:
# global_activity_buffer[activity_tool_path][thread_id] = ActivityBuffer # global_activity_buffer[activity_tool_path][thread_id] = ActivityBuffer
global_activity_buffer = {} global_activity_buffer = defaultdict(dict)
from thread import get_ident, allocate_lock from thread import get_ident
global_activity_buffer_lock = allocate_lock()
def registerActivity(activity): def registerActivity(activity):
# Must be rewritten to register # Must be rewritten to register
...@@ -1032,26 +1032,12 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1032,26 +1032,12 @@ class ActivityTool (Folder, UniqueObject):
is True, create one. is True, create one.
Intermediate level is unconditionaly created if non existant because Intermediate level is unconditionaly created if non existant because
chances are it will be used in the instance life. chances are it will be used in the instance life.
Lock is held when checking for intermediate level existance
because:
- intermediate level dict must not be created in 2 threads at the
same time, since one creation would destroy the existing one.
It's released after that step because:
- lower level access is at thread scope, thus by definition there
can be only one access at a time to a key
- GIL protects us when accessing python instances
""" """
# Safeguard: make sure we are wrapped in acquisition context before # Safeguard: make sure we are wrapped in acquisition context before
# using our path as an activity tool instance-wide identifier. # using our path as an activity tool instance-wide identifier.
assert getattr(self, 'aq_self', None) is not None assert getattr(self, 'aq_self', None) is not None
my_instance_key = self.getPhysicalPath() my_instance_key = self.getPhysicalPath()
my_thread_key = get_ident() my_thread_key = get_ident()
global_activity_buffer_lock.acquire()
try:
if my_instance_key not in global_activity_buffer:
global_activity_buffer[my_instance_key] = {}
finally:
global_activity_buffer_lock.release()
thread_activity_buffer = global_activity_buffer[my_instance_key] thread_activity_buffer = global_activity_buffer[my_instance_key]
try: try:
return thread_activity_buffer[my_thread_key] return thread_activity_buffer[my_thread_key]
......
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