Chromium Code Reviews| 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() |
|
Dirk Pranke
2011/09/14 20:00:39
Why RLock instead of Lock()?
M-A Ruel
2011/09/14 20:03:03
I'll need a RLock due to some locking recursion wh
|
| + @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): |
|
Dirk Pranke
2011/09/14 20:00:39
Do you really need a lock here? Isn't this guarant
M-A Ruel
2011/09/14 20:03:03
More or less but I want to reduce the GIL assumpti
|
| + return tuple(self._requirements) |
| + |
| class ExecutionQueue(object): |
| """Runs a set of WorkItem that have interdependencies and were WorkItem are |