Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/MailManager.cc @ 662:6dd6145eb1a5 draft
merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 02 Dec 2009 20:44:01 +0900 |
parents | 470db907a460 aefb5ee6fcd0 |
children | cc1b7333de92 |
rev | line source |
---|---|
50 | 1 #include <stdlib.h> |
2 #include "MailManager.h" | |
3 | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
4 void |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
5 MailManager::calc_mask(unsigned int qsize) |
50 | 6 { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
7 mask = 1; |
651 | 8 while(qsize>mask) { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
9 mask <<= 1; |
50 | 10 } |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
11 size = mask; |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
12 mask--; |
50 | 13 } |
14 | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
15 MailManager::MailManager(unsigned int qsize) { |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
16 calc_mask(qsize); |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
17 queue = New(memaddr,size); |
50 | 18 } |
19 | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
20 MailManager::~MailManager() { free(queue); } |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
21 |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
22 int |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
23 MailManager::count() |
50 | 24 { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
25 return (write+size-read)&mask; |
50 | 26 } |
27 | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
28 void |
651 | 29 MailManager::extend() |
30 { | |
31 memaddr *newq = New(memaddr,size*2); | |
660 | 32 unsigned int i = 0; |
651 | 33 while(i<size) { |
34 newq[i++] = queue[read++]; | |
35 read &= mask; | |
36 } | |
37 read = 0; write = i; | |
38 calc_mask(size*2); | |
39 free(queue); | |
40 queue = newq; | |
41 } | |
42 | |
43 void | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
44 MailManager::send(memaddr data) |
50 | 45 { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
46 queue[write++] = data; |
649 | 47 write &= mask; |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
48 if (write==read) { |
652 | 49 extend(); |
194 | 50 } |
50 | 51 } |
52 | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
53 memaddr |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
54 MailManager::recv() |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
55 { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
56 memaddr data; |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
57 if (count()>0) { |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
58 data = queue[read++]; |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
59 read &= mask; |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
60 } else { |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
61 data = 0; |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
62 } |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
63 return data; |
643 | 64 } |
65 | |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
66 /* end */ |