Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/MailManager.cc @ 1186:4c209dd223cd draft
fix MailManager and Semaphore
author | Daichi TOMA |
---|---|
date | Mon, 04 Jul 2011 14:11:26 +0900 |
parents | 2e20d2bb55c6 |
children | d4311f83377a |
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); |
1180 | 19 |
1186 | 20 queue_remain = new Sem(size-1); //queue内にあと入る数 |
21 queue_count = new Sem(0); //queue内に現在入っている数 | |
1180 | 22 |
50 | 23 } |
24 | |
1180 | 25 MailManager::~MailManager() |
26 { | |
27 free(queue); | |
1186 | 28 delete queue_remain; |
29 delete queue_count; | |
1180 | 30 } |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
31 |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
32 int |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
33 MailManager::count() |
50 | 34 { |
1186 | 35 return queue_count->count(); |
651 | 36 } |
37 | |
38 void | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
39 MailManager::send(memaddr data) |
50 | 40 { |
1186 | 41 queue_remain->sem_p(); //資源-1 |
1180 | 42 |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
43 queue[write++] = data; |
1186 | 44 //maskの範囲を超えた場合、0に戻す |
649 | 45 write &= mask; |
1180 | 46 |
1186 | 47 queue_count->sem_v(); //資源+1 |
50 | 48 } |
49 | |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
50 memaddr |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
51 MailManager::recv() |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
52 { |
1186 | 53 queue_count->sem_p(); //資源-1 |
1180 | 54 |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
55 memaddr data; |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
56 data = queue[read++]; |
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
57 read &= mask; |
1186 | 58 |
59 queue_remain->sem_v(); //資源+1 | |
1180 | 60 |
647
7ba4ad4538b1
MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
644
diff
changeset
|
61 return data; |
643 | 62 } |
63 | |
640
ecf056ddd21a
SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
64 /* end */ |