Mercurial > hg > Game > Cerium
diff TaskManager/kernel/ppe/HTaskInfo.cc @ 46:f154d9d07a42
*** empty log message ***
author | gongo |
---|---|
date | Fri, 15 Feb 2008 13:09:43 +0900 |
parents | |
children | 90523ccc4dff |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/HTaskInfo.cc Fri Feb 15 13:09:43 2008 +0900 @@ -0,0 +1,87 @@ +#include <stdio.h> +#include <stdlib.h> +#include "HTaskInfo.h" + +HTaskInfo::HTaskInfo(void) + :htaskPool(NULL), freeHTask(NULL) {} + +HTaskInfo::~HTaskInfo(void) { destroy(); } + +int +HTaskInfo::init(int num) +{ + if (htaskPool == NULL) { + return extend_pool(num); + } + return 0; +} + +/** + * Fix me + * extend できる限界を設定するべき? + */ +int +HTaskInfo::extend_pool(int num) +{ + HTaskPtr q = NULL; + + q = (HTaskPtr)malloc(sizeof(HTask)*(num+1)); + + if (q == NULL) { + return -1; + } + q->next = htaskPool; + htaskPool = q; + + /* Connect all free queue in the pool */ + for (q = htaskPool + 1; --num > 0; q++) { + q->next = q + 1; + } + q->next = freeHTask; + freeHTask = htaskPool + 1; + + return 0; +} + +HTaskPtr +HTaskInfo::create(int cmd, int size, + unsigned long long in_addr, + unsigned long long out_addr) +{ + HTaskPtr q; + + if (freeHTask == NULL) { + extend_pool(100); + } + + q = freeHTask; + freeHTask = freeHTask->next; + + q->command = cmd; + q->in_addr = in_addr; + q->out_addr = out_addr; + q->in_size = size; + q->wait_me = NULL; + q->wait_i = NULL; + q->post_func = NULL; + + return q; +} + +void +HTaskInfo::free(HTaskPtr q) +{ + q->next = freeHTask; + freeHTask = q; +} + +void +HTaskInfo::destroy(void) +{ + HTaskPtr q; + + for (q = htaskPool; q; q = q->next) { + free(q); + } + freeHTask = htaskPool = NULL; +}