Mercurial > hg > Members > kono > Cerium
view TaskManager/kernel/ppe/TaskQueueInfo.cc @ 47:8266445bdac2
*** empty log message ***
author | gongo |
---|---|
date | Fri, 15 Feb 2008 13:09:58 +0900 |
parents | f154d9d07a42 |
children | dd33ec2e51b9 |
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; 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; if (freeTaskQueue == NULL) { extend_pool(100); } q = freeTaskQueue; freeTaskQueue = freeTaskQueue->next; q->task = task; q->next = NULL; return q; } void TaskQueueInfo::free(TaskQueuePtr q) { 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; } }