Mercurial > hg > Members > kono > Cerium
changeset 958:58ff7b6fdbce
add freeOnce()
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 04 Aug 2010 17:42:36 +0900 |
parents | 559d041313dc |
children | 66cddab9fa76 |
files | TaskManager/kernel/ppe/HTask.h TaskManager/kernel/ppe/QueueInfo.h TaskManager/kernel/ppe/TaskList.h TaskManager/kernel/ppe/TaskQueue.h |
diffstat | 4 files changed, 34 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/kernel/ppe/HTask.h Wed Aug 04 17:07:37 2010 +0900 +++ b/TaskManager/kernel/ppe/HTask.h Wed Aug 04 17:42:36 2010 +0900 @@ -68,6 +68,11 @@ wait_i = new QueueInfo<TaskQueue>(taskQueuePool); } + void freeOnce() { + delete wait_me; + delete wait_i; + } + private: int param_index;
--- a/TaskManager/kernel/ppe/QueueInfo.h Wed Aug 04 17:07:37 2010 +0900 +++ b/TaskManager/kernel/ppe/QueueInfo.h Wed Aug 04 17:42:36 2010 +0900 @@ -14,6 +14,9 @@ T *next; T *prev; + void initOnce(); // to initialize object in pool + void freeOnce(); // to destroy object in pool + // virual void init(); }; #endif @@ -22,9 +25,17 @@ public: /* constructor */ + + /** + singleton constructor + use this in non initialize envrionment is wrong. + */ QueueInfo<T>(){ queueInfoInit(); } + /** + normal constructor requires + */ QueueInfo<T>(QueueInfo<T> *p) { queueInfoInit(); queuePool = p; @@ -58,6 +69,7 @@ private: /* variables */ + /* we cannot use static in template */ /* static */ QueueInfo<T> *queuePool; T* first; T* last; @@ -76,9 +88,15 @@ #include <stdlib.h> -// Singleton T Pool -// you have to define it at where you want to use. -// template<typename T>static QueueInfo<T> QueueInfo<T>::queuePool; +/** + singleton constructor + all queueInfo should share this as a pool. + + exteren QueueInfo<H> pool; + QueueInfo<H> pool = new QueueInfo<H>(); + + use this in non initialize envrionment is wrong. +*/ template<typename T>void QueueInfo<T>::queueInfoInit() { // 最初の一つは自分 @@ -92,11 +110,16 @@ for(T * p = queuePool->waiter; p; ) { T * next = p->waiter; p->waiter = NULL; + p->freeOnce(); free(p); p = next; } } +/** + all pools are shared among QueueInfo (separated by size and type). + it automatically extended by 64. + */ template<typename T>int QueueInfo<T>::extend_pool(int num) {