Mercurial > hg > Game > Cerium
view TaskManager/kernel/ppe/HTaskInfo.cc @ 497:3429986b8a28 draft
no wakeup loop
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 10 Oct 2009 21:05:55 +0900 |
parents | 75e4afa40da2 |
children | bce667ff20b9 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "TaskManagerImpl.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->wait_me = new TaskQueueInfo(); q->wait_i = new TaskQueueInfo(); q->inData = (ListDataPtr)malloc(sizeof(ListData)); q->outData = (ListDataPtr)malloc(sizeof(ListData)); } q->next = freeHTask; q->inData = (ListDataPtr)malloc(sizeof(ListData)); q->outData = (ListDataPtr)malloc(sizeof(ListData)); q->wait_me = new TaskQueueInfo(); q->wait_i = new TaskQueueInfo(); freeHTask = htaskPool + 1; return 0; } /** * Task をプールから取って来て返す * * @param [cmd] タスクコマンド */ HTaskPtr HTaskInfo::create(int cmd) { HTaskPtr q; if (freeHTask == NULL) { extend_pool(100); } q = freeHTask; freeHTask = freeHTask->next; q->command = cmd; q->inData->clear(); q->outData->clear(); q->self = (TaskQueuePtr) q; q->param_size = 0; q->post_func = NULL; q->mimpl = NULL; q->cpu_type = CPU_PPE; return q; } void HTaskInfo::free(HTaskPtr q) { q->next = freeHTask; freeHTask = q; } void HTaskInfo::destroy(void) { HTaskPtr q, tmp; #if 1 q = htaskPool; while (q) { tmp = q->next; free(q); q = tmp; } #else for (q = htaskPool; q; q = q->next) { free(q); } #endif freeHTask = htaskPool = NULL; }