Mercurial > hg > Game > Cerium
view TaskManager/Fifo/MailManager.cc @ 6:39ce245235d4
*** empty log message ***
author | gongo |
---|---|
date | Wed, 06 Feb 2008 11:41:08 +0900 |
parents | 75f184d16fa5 |
children | 98bb1b2bb71e |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "MailManager.h" int MailManager::init_pool_mailQueue(int num) { if (!mailQueuePool) { return extend_pool_mailQueue(num); } return 0; } int MailManager::extend_pool_mailQueue(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_mail(unsigned int data) { return get_free_mailQueue(data); } MailQueuePtr MailManager::get_free_mailQueue(unsigned int data) { MailQueuePtr q; if (!freeMailQueue) { extend_pool_mailQueue(30); } q = freeMailQueue; freeMailQueue = freeMailQueue->next; q->data = data; q->next = NULL; return q; } void MailManager::free_mailQueue(MailQueuePtr q) { q->next = freeMailQueue; freeMailQueue = q; } MailQueuePtr 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; } }