Commit 2fe481c8 authored by Vincent Pelletier's avatar Vincent Pelletier

Prune entries with 0 refcount.

Also, factorise refcount code.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2558 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 52eff34f
...@@ -61,10 +61,26 @@ class Dispatcher: ...@@ -61,10 +61,26 @@ class Dispatcher:
return False return False
elif queue is NOBODY: elif queue is NOBODY:
return True return True
self.queue_dict[id(queue)] -= 1 self._decrefQueue(queue)
queue.put(data) queue.put(data)
return True return True
def _decrefQueue(self, queue):
queue_id = id(queue)
queue_dict = self.queue_dict
if queue_dict[queue_id] == 1:
queue_dict.pop(queue_id)
else:
queue_dict[queue_id] -= 1
def _increfQueue(self, queue):
queue_id = id(queue)
queue_dict = self.queue_dict
try:
queue_dict[queue_id] += 1
except KeyError:
queue_dict[queue_id] = 1
def needPollThread(self): def needPollThread(self):
self.poll_thread.start() self.poll_thread.start()
...@@ -75,12 +91,7 @@ class Dispatcher: ...@@ -75,12 +91,7 @@ class Dispatcher:
if self.poll_thread is not None: if self.poll_thread is not None:
self.needPollThread() self.needPollThread()
self.message_table.setdefault(id(conn), {})[msg_id] = queue self.message_table.setdefault(id(conn), {})[msg_id] = queue
queue_dict = self.queue_dict self._increfQueue(queue)
key = id(queue)
try:
queue_dict[key] += 1
except KeyError:
queue_dict[key] = 1
@profiler_decorator @profiler_decorator
def unregister(self, conn): def unregister(self, conn):
...@@ -92,7 +103,7 @@ class Dispatcher: ...@@ -92,7 +103,7 @@ class Dispatcher:
finally: finally:
self.lock_release() self.lock_release()
notified_set = set() notified_set = set()
queue_dict = self.queue_dict _decrefQueue = self._decrefQueue
for queue in message_table.itervalues(): for queue in message_table.itervalues():
if queue is NOBODY: if queue is NOBODY:
continue continue
...@@ -100,7 +111,7 @@ class Dispatcher: ...@@ -100,7 +111,7 @@ class Dispatcher:
if queue_id not in notified_set: if queue_id not in notified_set:
queue.put((conn, None)) queue.put((conn, None))
notified_set.add(queue_id) notified_set.add(queue_id)
queue_dict[queue_id] -= 1 _decrefQueue(queue)
@giant_lock @giant_lock
@profiler_decorator @profiler_decorator
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment