Mercurial > hg > Game > Cerium
view TaskManager/kernel/ppe/BufferManager.cc @ 93:dd33ec2e51b9
*** empty log message ***
author | gongo |
---|---|
date | Thu, 28 Feb 2008 17:32:18 +0900 |
parents | 504899860e66 |
children | 588ab5f0e659 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "BufferManager.h" BufferManager::BufferManager(int num) :machineNum(num), activeTaskQueue(NULL), waitTaskQueue(NULL) {} BufferManager::~BufferManager(void) { finish(); } void BufferManager::init(void) { taskListImpl = new TaskListInfo; taskQueueImpl = new TaskQueueInfo; htaskImpl = new HTaskInfo; taskListImpl->init(machineNum*2); taskQueueImpl->init(TASK_MAX_SIZE*4); htaskImpl->init(TASK_MAX_SIZE*2); mainTaskList = taskListImpl->create(); } TaskQueuePtr BufferManager::create_taskQueue(HTaskPtr task) { return taskQueueImpl->create(task); } HTaskPtr //BufferManager::create_task(int cmd, int siz, DmaBuffer *in, DmaBuffer *out) BufferManager::create_task(int cmd, int siz, unsigned int in, unsigned int out) { return htaskImpl->create(cmd, siz, in, out); } void BufferManager::free_taskQueue(TaskQueuePtr q) { taskQueueImpl->free(q); } void BufferManager::free_task(HTaskPtr task) { htaskImpl->free(task); } void BufferManager::append_activeTask(HTaskPtr task) { TaskQueuePtr q; q = taskQueueImpl->create(task); activeTaskQueue = taskQueueImpl->append(activeTaskQueue, q); } void BufferManager::finish(void) { delete taskListImpl; delete taskQueueImpl; delete htaskImpl; } void BufferManager::append_waitTask(HTaskPtr task) { TaskQueuePtr q; q = taskQueueImpl->create(task); waitTaskQueue = taskQueueImpl->append(waitTaskQueue, q); } void BufferManager::check_task_finish(HTaskPtr task) { notify_wait_taskQueue(task, task->wait_me); task->post_func(); htaskImpl->free(task); } void BufferManager::notify_wait_taskQueue(HTaskPtr depend, TaskQueuePtr list) { TaskQueuePtr p; HTaskPtr task; p = list; // wait task list while (p) { task = p->task; task->wait_i = remove_taskQueue_eq_task(task->wait_i, depend); if (task->wait_i == NULL) { append_activeTask(task); waitTaskQueue = remove_taskQueue_eq_task(waitTaskQueue, task); } p = p->next; } remove_taskQueue_all(list); } void BufferManager::remove_taskQueue_all(TaskQueuePtr list) { TaskQueuePtr p = list; TaskQueuePtr p1; while (p != NULL) { p1 = p->next; taskQueueImpl->free(p); p = p1; } } TaskQueuePtr BufferManager::remove_taskQueue_eq_task(TaskQueuePtr list, HTaskPtr task) { TaskQueuePtr p = list; TaskQueuePtr p1; if (!p) return p; if (p->task == task) { list = list->next; taskQueueImpl->free(p); } else { p1 = p->next; while (p1 && p1->task && p1->task != task) { p1 = p1->next; p = p->next; } if (p1) { p->next = p1->next; taskQueueImpl->free(p1); } } return list; } TaskQueuePtr BufferManager::remove_taskQueue(TaskQueuePtr list, TaskQueuePtr q) { TaskQueuePtr p = list; TaskQueuePtr p1; if (!p) return p; if (p == q) { list = list->next; taskQueueImpl->free(p); } else { p1 = p->next; while (p1 && p1 != q) { p1 = p1->next; p = p->next; } if (p1) { p->next = p1->next; taskQueueImpl->free(p1); } } return list; } TaskListPtr BufferManager::get_available_taskList(void) { TaskListPtr list, q; list = mainTaskList; while (list->next) list = list->next; if (list->length < TASK_MAX_SIZE) { return list; } else { q = taskListImpl->create(); mainTaskList = taskListImpl->append(mainTaskList, q); return q; } } void BufferManager::clear_taskList(void) { TaskListPtr p, p1; mainTaskList->length = 0; p = mainTaskList->next; while (p) { p1 = p; p = p->next; taskListImpl->free(p1); } }