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

Unified Diff: gclient_utils.py

Issue 2049583003: Add resource locking in gclient (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Review and fix Created 4 years, 6 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') | no next file » | 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 9d1b9dfdd19b981172f19df83e360d12d935dfe6..76cbe2df1de8a903fcdb70c1ab16cc7f7eaebefa 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -784,6 +784,7 @@ class WorkItem(object):
self._name = name
self.outbuf = cStringIO.StringIO()
self.start = self.finish = None
+ self.resources = [] # List of resources this work item requires.
def run(self, work_queue):
"""work_queue is passed as keyword argument so it should be
@@ -869,6 +870,15 @@ class ExecutionQueue(object):
----------------------------------------""" % (
task.name, comment, elapsed, task.outbuf.getvalue().strip())
+ def _is_conflict(self, job):
+ """Checks to see if a job will conflict with another running job."""
+ for running_job in self.running:
+ for used_resource in running_job.item.resources:
+ logging.debug('Checking resource %s' % used_resource)
+ if used_resource in job.resources:
+ return True
+ return False
+
def flush(self, *args, **kwargs):
"""Runs all enqueued items until all are executed."""
kwargs['work_queue'] = self
@@ -892,9 +902,10 @@ class ExecutionQueue(object):
# Verify its requirements.
if (self.ignore_requirements or
not (set(self.queued[i].requirements) - set(self.ran))):
- # Start one work item: all its requirements are satisfied.
- self._run_one_task(self.queued.pop(i), args, kwargs)
- break
+ if not self._is_conflict(self.queued[i]):
+ # Start one work item: all its requirements are satisfied.
+ self._run_one_task(self.queued.pop(i), args, kwargs)
+ break
else:
# Couldn't find an item that could run. Break out the outher loop.
break
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698