From 189d27140538adac27dd32cbf5023339e477ead8 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Sat, 17 Jul 2010 22:25:27 +0200 Subject: [PATCH] workerpool: Use common function to add tasks Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/workerpool.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/workerpool.py b/lib/workerpool.py index 0ca9155c6..d2fbfddbd 100644 --- a/lib/workerpool.py +++ b/lib/workerpool.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2008 Google Inc. +# Copyright (C) 2008, 2009, 2010 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -189,6 +189,14 @@ class WorkerPool(object): while self._quiescing: self._pool_to_pool.wait() + def _AddTaskUnlocked(self, args): + assert isinstance(args, (tuple, list)), "Arguments must be a sequence" + + self._tasks.append(args) + + # Notify a waiting worker + self._pool_to_worker.notify() + def AddTask(self, *args): """Adds a task to the queue. @@ -198,11 +206,7 @@ class WorkerPool(object): self._lock.acquire() try: self._WaitWhileQuiescingUnlocked() - - self._tasks.append(args) - - # Wake one idling worker up - self._pool_to_worker.notify() + self._AddTaskUnlocked(args) finally: self._lock.release() @@ -220,10 +224,8 @@ class WorkerPool(object): try: self._WaitWhileQuiescingUnlocked() - self._tasks.extend(tasks) - - for _ in tasks: - self._pool_to_worker.notify() + for args in tasks: + self._AddTaskUnlocked(args) finally: self._lock.release() -- GitLab