Mercurial > hg > Game > Cerium
changeset 820:3c508c837ad8 draft
give up singleton pattern.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 23 May 2010 11:30:39 +0900 |
parents | c13fffba095d |
children | 4691b6ae44ec |
files | TaskManager/kernel/ppe/QueueInfo.h example/task_queue/testQueueInfo.cc |
diffstat | 2 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/kernel/ppe/QueueInfo.h Sun May 23 10:55:52 2010 +0900 +++ b/TaskManager/kernel/ppe/QueueInfo.h Sun May 23 11:30:39 2010 +0900 @@ -22,6 +22,9 @@ public: /* constructor */ QueueInfo<T>(); + QueueInfo<T>(QueueInfo<T> *p) { + queuePool = p; + } BASE_NEW_DELETE(QueueInfo); @@ -49,7 +52,7 @@ private: /* variables */ - static QueueInfo<T> queuePool; + /* static */ QueueInfo<T> *queuePool; T* first; T* last; @@ -79,7 +82,7 @@ template<typename T>void QueueInfo<T>::freePool() { - for(T * p = queuePool.waiter; p; ) { + for(T * p = queuePool->waiter; p; ) { T * next = p->waiter; p->waiter = NULL; free(p); @@ -100,7 +103,7 @@ T * p = q; for (; num-- > 0; p++) { p->waiter = NULL; - queuePool.addLast(p); + queuePool->addLast(p); } return 0; @@ -114,10 +117,10 @@ template<typename T>T * QueueInfo<T>::create() { - T * q = queuePool.poll(); + T * q = queuePool->poll(); if (! q) { - queuePool.extend_pool(64); - q = queuePool.poll(); + queuePool->extend_pool(64); + q = queuePool->poll(); } q->init(); return q; @@ -128,7 +131,7 @@ QueueInfo<T>::free_(T * q) { q->waiter = NULL; - queuePool.addLast(q); + queuePool->addLast(q); }
--- a/example/task_queue/testQueueInfo.cc Sun May 23 10:55:52 2010 +0900 +++ b/example/task_queue/testQueueInfo.cc Sun May 23 11:30:39 2010 +0900 @@ -6,14 +6,15 @@ #include "Func.h" -static QueueInfo<TaskList, TaskList>::queuePool; +// static QueueInfo<TaskList, TaskList>::queuePool; +static QueueInfo<TaskList> *queuePool = new QueueInfo<TaskList>() ; void queueInfoTest(int count) { - QueueInfo<TaskList> *q = new QueueInfo<TaskList>() ; - QueueInfo<TaskList> *r = new QueueInfo<TaskList>() ; + QueueInfo<TaskList> *q = new QueueInfo<TaskList>(queuePool) ; + QueueInfo<TaskList> *r = new QueueInfo<TaskList>(queuePool) ; int i = 0; for (i = 0; i < count; i++) {