summaryrefslogtreecommitdiff
path: root/lib/git/async/util.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-06-08 00:32:33 +0200
committerSebastian Thiel <byronimo@gmail.com>2010-06-08 00:32:33 +0200
commit5d996892ac76199886ba3e2754ff9c9fac2456d6 (patch)
tree01477d86a366e77e346150300efc505730a52010 /lib/git/async/util.py
parent3e2ba9c2028f21d11988558f3557905d21e93808 (diff)
downloadgitpython-5d996892ac76199886ba3e2754ff9c9fac2456d6.tar.gz
test implementation of async-queue with everything stripped from it that didn't seem necessary - its a failure, something is wrong - performance not much better than the original one, its depending on the condition performance actually, which I don't get faster
Diffstat (limited to 'lib/git/async/util.py')
-rw-r--r--lib/git/async/util.py53
1 files changed, 48 insertions, 5 deletions
diff --git a/lib/git/async/util.py b/lib/git/async/util.py
index 55766579..e3556c05 100644
--- a/lib/git/async/util.py
+++ b/lib/git/async/util.py
@@ -133,12 +133,55 @@ class HSCondition(_Condition):
class AsyncQueue(Queue):
"""A queue using different condition objects to gain multithreading performance"""
+ __slots__ = ('mutex', 'not_empty', 'queue')
+
def __init__(self, maxsize=0):
- Queue.__init__(self, maxsize)
-
+ self.queue = deque()
+ self.mutex = Lock()
self.not_empty = HSCondition(self.mutex)
- self.not_full = HSCondition(self.mutex)
- self.all_tasks_done = HSCondition(self.mutex)
-
+ def qsize(self):
+ self.mutex.acquire()
+ try:
+ return len(self.queue)
+ finally:
+ self.mutex.release()
+
+ def empty(self):
+ self.mutex.acquire()
+ try:
+ return not len(self.queue)
+ finally:
+ self.mutex.release()
+
+ def put(self, item, block=True, timeout=None):
+ self.mutex.acquire()
+ self.queue.append(item)
+ self.mutex.release()
+ self.not_empty.notify()
+
+ def get(self, block=True, timeout=None):
+ self.not_empty.acquire()
+ q = self.queue
+ try:
+ if not block:
+ if not len(q):
+ raise Empty
+ elif timeout is None:
+ while not len(q):
+ self.not_empty.wait()
+ elif timeout < 0:
+ raise ValueError("'timeout' must be a positive number")
+ else:
+ endtime = _time() + timeout
+ while not len(q):
+ remaining = endtime - _time()
+ if remaining <= 0.0:
+ raise Empty
+ self.not_empty.wait(remaining)
+ return q.popleft()
+ finally:
+ self.not_empty.release()
+
+
#} END utilities