Mercurial > hg > Members > kono > Cerium
view TaskManager/kernel/ppe/MailManager.cc @ 639:70c5c2d2eb24
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 19 Nov 2009 18:45:24 +0900 |
parents | 42c94f85c779 |
children | a909c50081c2 |
line wrap: on
line source
#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(memaddr 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; #if 0 for (q = mailQueuePool; q; q = q->next) { free(q); } #else q = mailQueuePool; while (q) { MailQueuePtr tmp = q->next; free(q); q = tmp; } #endif 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; } }