Mercurial > hg > Game > Cerium
view TaskManager/kernel/ppe/MailManager.cc @ 70:178459e03f5c
*** empty log message ***
author | gongo |
---|---|
date | Mon, 18 Feb 2008 01:13:00 +0900 |
parents | 7927e00fb8e2 |
children | b56fb6ac2fc4 |
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(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; } }