Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/MailManager.cc @ 1531:4443d59a8210 draft
SDL.h in main.cc
author | yuhi@cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 07 Dec 2012 15:46:27 +0900 |
parents | 898fdcf53c31 |
children | 5238ca826d6e |
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) { |
719
cc1b7333de92
clean up scheduler main loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
662
diff
changeset
|
16 read = write = 0; |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
17 calc_mask(qsize); |
868
08ed5e750d78
[aquarium]: update screen scope on linda with protobuf
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
719
diff
changeset
|
18 queue = Newq(memaddr,size); |
1189 | 19 } |
1180 | 20 |
1189 | 21 MailManager::~MailManager() { free(queue); } |
1180 | 22 |
1189 | 23 int |
24 MailManager::count() | |
25 { | |
26 return (write+size-read)&mask; | |
50 | 27 } |
28 | |
1189 | 29 void |
30 MailManager::extend() | |
1180 | 31 { |
1189 | 32 memaddr *newq = Newq(memaddr,size*2); |
33 unsigned int i = 0; | |
34 while(i<size) { | |
35 newq[i++] = queue[read++]; | |
36 read &= mask; | |
37 } | |
38 read = 0; write = i; | |
39 calc_mask(size*2); | |
40 free(queue); | |
41 queue = newq; | |
651 | 42 } |
43 | |
44 void | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
45 MailManager::send(memaddr data) |
50 | 46 { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
47 queue[write++] = data; |
649 | 48 write &= mask; |
1189 | 49 if (write==read) { |
50 extend(); | |
51 } | |
50 | 52 } |
53 | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
54 memaddr |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
55 MailManager::recv() |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
56 { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
57 memaddr data; |
1189 | 58 if (count()>0) { |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
59 data = queue[read++]; |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
60 read &= mask; |
1189 | 61 } else { |
62 data = 0; | |
63 } | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
64 return data; |
643 | 65 } |
66 | |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
67 /* end */ |