diff TaskManager/kernel/ppe/MailManager.cc @ 50:7927e00fb8e2

*** empty log message ***
author gongo
date Fri, 15 Feb 2008 19:36:08 +0900
parents
children 72dcf908ec52
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/kernel/ppe/MailManager.cc	Fri Feb 15 19:36:08 2008 +0900
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "MailManager.h"
+
+MailManager::MailManager(void)
+    :mailQueuePool(NULL), freeMailQueue(NULL) {}
+
+MailManager::~MailManager(void) { destroy(); }
+
+int
+MailManager::init(int num)
+{
+    if (!mailQueuePool) {
+	return extend_pool(num);
+    }
+    return 0;
+}
+
+int
+MailManager::extend_pool(int num)
+{
+    MailQueuePtr q;
+	
+    q = (MailQueuePtr)malloc(sizeof(MailQueue)*(num+1));
+	
+    if (q == NULL) {
+	return -1;
+    }
+    q->next = mailQueuePool;
+    mailQueuePool = q;
+	
+    /* Connect all free queue in the pool */
+    for (q = mailQueuePool + 1; --num > 0; q++) {
+	q->next = q + 1;
+    }
+    q->next = freeMailQueue;
+    freeMailQueue = mailQueuePool + 1;
+	
+    return 0;
+}
+
+MailQueuePtr
+MailManager::create(unsigned int data)
+{
+    MailQueuePtr q;
+	
+    if (!freeMailQueue) {
+	extend_pool(30);
+    }
+    q = freeMailQueue;
+    freeMailQueue = freeMailQueue->next;
+	
+    q->data = data;
+    q->next = NULL;
+	
+    return q;
+}
+
+void
+MailManager::free(MailQueuePtr q)
+{
+    q->next = freeMailQueue;
+    freeMailQueue = q;
+}
+
+
+void
+MailManager::destroy(void)
+{
+    MailQueuePtr q;
+
+    for (q = mailQueuePool; q; q = q->next) {
+	free(q);
+    }
+    freeMailQueue = mailQueuePool = NULL;
+}
+
+
+MailQueuePtr
+MailManager::append_mailQueue(MailQueuePtr list, MailQueuePtr q)
+{
+    MailQueuePtr p = list;
+	
+    if (p == NULL) {
+	return q;
+    } else {
+	while(p->next) p = p->next;
+	p->next = q;
+	return list;
+    }
+}