Mercurial > hg > Members > kono > Cerium
comparison TaskManager/kernel/ppe/MailManager.cc @ 50:7927e00fb8e2
*** empty log message ***
author | gongo |
---|---|
date | Fri, 15 Feb 2008 19:36:08 +0900 |
parents | |
children | 72dcf908ec52 |
comparison
equal
deleted
inserted
replaced
49:64ef030deb22 | 50:7927e00fb8e2 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include "MailManager.h" | |
4 | |
5 MailManager::MailManager(void) | |
6 :mailQueuePool(NULL), freeMailQueue(NULL) {} | |
7 | |
8 MailManager::~MailManager(void) { destroy(); } | |
9 | |
10 int | |
11 MailManager::init(int num) | |
12 { | |
13 if (!mailQueuePool) { | |
14 return extend_pool(num); | |
15 } | |
16 return 0; | |
17 } | |
18 | |
19 int | |
20 MailManager::extend_pool(int num) | |
21 { | |
22 MailQueuePtr q; | |
23 | |
24 q = (MailQueuePtr)malloc(sizeof(MailQueue)*(num+1)); | |
25 | |
26 if (q == NULL) { | |
27 return -1; | |
28 } | |
29 q->next = mailQueuePool; | |
30 mailQueuePool = q; | |
31 | |
32 /* Connect all free queue in the pool */ | |
33 for (q = mailQueuePool + 1; --num > 0; q++) { | |
34 q->next = q + 1; | |
35 } | |
36 q->next = freeMailQueue; | |
37 freeMailQueue = mailQueuePool + 1; | |
38 | |
39 return 0; | |
40 } | |
41 | |
42 MailQueuePtr | |
43 MailManager::create(unsigned int data) | |
44 { | |
45 MailQueuePtr q; | |
46 | |
47 if (!freeMailQueue) { | |
48 extend_pool(30); | |
49 } | |
50 q = freeMailQueue; | |
51 freeMailQueue = freeMailQueue->next; | |
52 | |
53 q->data = data; | |
54 q->next = NULL; | |
55 | |
56 return q; | |
57 } | |
58 | |
59 void | |
60 MailManager::free(MailQueuePtr q) | |
61 { | |
62 q->next = freeMailQueue; | |
63 freeMailQueue = q; | |
64 } | |
65 | |
66 | |
67 void | |
68 MailManager::destroy(void) | |
69 { | |
70 MailQueuePtr q; | |
71 | |
72 for (q = mailQueuePool; q; q = q->next) { | |
73 free(q); | |
74 } | |
75 freeMailQueue = mailQueuePool = NULL; | |
76 } | |
77 | |
78 | |
79 MailQueuePtr | |
80 MailManager::append_mailQueue(MailQueuePtr list, MailQueuePtr q) | |
81 { | |
82 MailQueuePtr p = list; | |
83 | |
84 if (p == NULL) { | |
85 return q; | |
86 } else { | |
87 while(p->next) p = p->next; | |
88 p->next = q; | |
89 return list; | |
90 } | |
91 } |