Mercurial > hg > Members > kono > Cerium
view TaskManager/kernel/ppe/TaskQueueInfo.cc @ 93:dd33ec2e51b9
*** empty log message ***
author | gongo |
---|---|
date | Thu, 28 Feb 2008 17:32:18 +0900 |
parents | f154d9d07a42 |
children | 588ab5f0e659 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "TaskQueueInfo.h" TaskQueueInfo::TaskQueueInfo(void) :taskQueuePool(NULL), freeTaskQueue(NULL) {} TaskQueueInfo::~TaskQueueInfo(void) { destroy(); } int TaskQueueInfo::init(int num) { if (taskQueuePool == NULL) { return extend_pool(num); } return 0; } int TaskQueueInfo::extend_pool(int num) { TaskQueuePtr q = NULL; static int i = 0; printf("extend %d\n", ++i); q = (TaskQueuePtr)malloc(sizeof(TaskQueue)*(num+1)); if (q == NULL) { return -1; } q->next = taskQueuePool; taskQueuePool = q; /* Connect all free queue in the pool */ for (q = taskQueuePool + 1; --num > 0; q++) { q->next = q + 1; } q->next = freeTaskQueue; freeTaskQueue = taskQueuePool + 1; return 0; } TaskQueuePtr TaskQueueInfo::create(HTaskPtr task) { TaskQueuePtr q; static int i = 0; printf("create %d\n", ++i); if (freeTaskQueue == NULL) { extend_pool(100); } q = freeTaskQueue; freeTaskQueue = freeTaskQueue->next; q->task = task; q->next = NULL; return q; } void TaskQueueInfo::free(TaskQueuePtr q) { static int i = 0; printf("free %d\n", ++i); printf("## command %d ##\n", q->task->command); q->next = freeTaskQueue; freeTaskQueue = q; } void TaskQueueInfo::destroy(void) { TaskQueuePtr q; for (q = taskQueuePool; q; q = q->next) { free(q); } freeTaskQueue = taskQueuePool = NULL; } TaskQueuePtr TaskQueueInfo::append(TaskQueuePtr list, TaskQueuePtr q) { TaskQueuePtr p = list; if (!p) { return q; } else { while(p->next) p = p->next; p->next = q; return list; } }