Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: gclient_utils.py

Issue 7909012: Retry "Initial step into making Dependency thread safe"" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: rebase against head Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gclient.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_utils.py
diff --git a/gclient_utils.py b/gclient_utils.py
index 89050b7add1469f184c83b1c636910e7aa88a04f..2402519a3351d6011dc1252f7d8922e7192f0cf5 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -456,19 +456,45 @@ def GetGClientRootAndEntries(path=None):
return config_dir, env['entries']
+def lockedmethod(method):
+ """Method decorator that holds self.lock for the duration of the call."""
+ def inner(self, *args, **kwargs):
+ try:
+ try:
+ self.lock.acquire()
+ except KeyboardInterrupt:
+ print >> sys.stderr, 'Was deadlocked'
+ raise
+ return method(self, *args, **kwargs)
+ finally:
+ self.lock.release()
+ return inner
+
+
class WorkItem(object):
"""One work item."""
- def __init__(self):
+ def __init__(self, name):
# A list of string, each being a WorkItem name.
- self.requirements = []
+ self._requirements = set()
# A unique string representing this work item.
- self.name = None
+ self._name = name
+ self.lock = threading.RLock()
+ @lockedmethod
def run(self, work_queue):
"""work_queue is passed as keyword argument so it should be
the last parameters of the function when you override it."""
pass
+ @property
+ def name(self):
+ return self._name
+
+ @property
+ @lockedmethod
+ def requirements(self):
+ return tuple(self._requirements)
+
class ExecutionQueue(object):
"""Runs a set of WorkItem that have interdependencies and were WorkItem are
« no previous file with comments | « gclient.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698