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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
1 #include <stdlib.h>
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
2 #include "MailManager.h"
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
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
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
6 {
647
7ba4ad4538b1 MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 644
diff changeset
7 mask = 1;
651
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 649
diff changeset
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
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
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
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
13 }
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
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
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
19
1186
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
20 queue_remain = new Sem(size-1); //queue内にあと入る数
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
21 queue_count = new Sem(0); //queue内に現在入っている数
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
22
50
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
23 }
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
24
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
25 MailManager::~MailManager()
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
26 {
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
27 free(queue);
1186
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
28 delete queue_remain;
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
29 delete queue_count;
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
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
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
34 {
1186
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
35 return queue_count->count();
651
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 649
diff changeset
36 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 649
diff changeset
37
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 649
diff changeset
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
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
40 {
1186
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
41 queue_remain->sem_p(); //資源-1
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
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
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
44 //maskの範囲を超えた場合、0に戻す
649
026e9e7f1402 MailManager Fifo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 647
diff changeset
45 write &= mask;
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
46
1186
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
47 queue_count->sem_v(); //資源+1
50
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
48 }
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
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
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
53 queue_count->sem_p(); //資源-1
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
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
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
58
4c209dd223cd fix MailManager and Semaphore
Daichi TOMA
parents: 1180
diff changeset
59 queue_remain->sem_v(); //資源+1
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
60
647
7ba4ad4538b1 MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 644
diff changeset
61 return data;
643
2a611e8d8788 minor fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 640
diff changeset
62 }
2a611e8d8788 minor fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 640
diff changeset
63
640
ecf056ddd21a SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 603
diff changeset
64 /* end */