diff TaskManager/kernel/ppe/BufferManager.cc @ 46:f154d9d07a42

*** empty log message ***
author gongo
date Fri, 15 Feb 2008 13:09:43 +0900
parents
children 8266445bdac2
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/kernel/ppe/BufferManager.cc	Fri Feb 15 13:09:43 2008 +0900
@@ -0,0 +1,192 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "TaskInfo.h"
+
+BufferManager::BufferManager(int num)
+    :machineNum(num), activeTaskQueue(NULL), waitTaskQueue(NULL) {}
+
+BufferManager::~BufferManager(void) { finish(); }
+
+void
+BufferManager::init(void)
+{
+    tlistImpl  = new TaskListInfo;
+    tqueueImpl = new TaskQueueInfo;
+    htaskImpl  = new HTaskInfo;
+
+    tlistImpl->init(machineNum*2);
+    tqueueImpl->init(TASK_MAX_SIZE*4);
+    htaskImpl->init(TASK_MAX_SIZE*2);
+    
+    machineTaskList = new TaskListPtr[machineNum];
+
+    for (int i = 0; i < machineNum; i++) {
+	machineTaskList[i] = tlistImpl->create();
+    }
+}
+
+TaskQueuePtr
+BufferManager::create_taskQueue(HTaskPtr task)
+{
+    return tqueueImpl->create(task);
+}
+
+HTaskPtr
+BufferManager::create_task(int cmd, int siz, uint64 in_addr, uint64 out_addr)
+{
+    return htaskImpl->create(cmd, siz, in_addr, out_addr);
+}
+
+void
+BufferManager::free_taskQueue(TaskQueuePtr q)
+{
+    tqueueImpl->free(q);
+}
+
+void
+BufferManager::free_task(HTaskPtr task)
+{
+    htaskImpl->free(task);
+}
+
+void
+BufferManager::append_activeTask(HTaskPtr task)
+{
+    TaskQueuePtr q;
+
+    q = tqueueImpl->create(task);
+    activeTaskQueue = tqueueImpl->append(activeTaskQueue, q);
+}
+
+void
+BufferManager::finish(void)
+{
+    delete tlistImpl;
+    delete tqueueImpl;
+    delete htaskImpl;
+}
+
+void
+BufferManager::append_waitTask(HTaskPtr task)
+{
+    TaskQueuePtr q;
+
+    q = tqueueImpl->create(task);
+    waitTaskQueue = tqueueImpl->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, d;
+    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) {
+	    d = p;
+	    p = p->next;
+	    append_activeTask(task);
+	    waitTaskQueue = remove_taskQueue(waitTaskQueue, d);
+	} else {
+	    p = p->next;
+	}
+    }
+}
+
+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;
+	tqueueImpl->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;
+	    tqueueImpl->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;
+	tqueueImpl->free(p);
+    } else {
+	p1 = p->next;
+	while (p1 && p1 != q) {
+	    p1 = p1->next;
+	    p = p->next;
+	}
+	if (p1) {
+	    p->next = p1->next;
+	    tqueueImpl->free(p1);
+	}
+    }
+
+    return list;    
+}
+
+TaskListPtr
+BufferManager::get_available_taskList(void)
+{
+    TaskListPtr list, q;
+
+    list = machineTaskList[0];
+
+    while (list->next) list = list->next;
+
+    if (list->length < TASK_MAX_SIZE) {
+	return list;
+    } else {
+	q = tlistImpl->create();
+	machineTaskList[0] = tlistImpl->append(machineTaskList[0], q);
+	return q;
+    }
+}
+
+void
+BufferManager::clear_taskList(void)
+{
+    TaskListPtr p, p1;
+
+    machineTaskList[0]->length = 0;
+
+    p = machineTaskList[0]->next;
+    while (p) {
+	p1 = p;
+	p = p->next;
+	tlistImpl->free(p1);
+    }
+}