annotate TaskManager/kernel/ppe/MailManager.cc @ 1189:898fdcf53c31 draft

add SemMailManager
author Daichi TOMA
date Fri, 08 Jul 2011 18:34:18 +0900
parents d4311f83377a
children 5238ca826d6e
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);
1189
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
19 }
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
20
1189
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
21 MailManager::~MailManager() { free(queue); }
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
22
1189
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
23 int
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
24 MailManager::count()
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
25 {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
26 return (write+size-read)&mask;
50
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
27 }
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
28
1189
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
29 void
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
30 MailManager::extend()
1180
2e20d2bb55c6 change mailmanager to mail on semaphore
Daichi TOMA
parents: 868
diff changeset
31 {
1189
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
32 memaddr *newq = Newq(memaddr,size*2);
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
33 unsigned int i = 0;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
34 while(i<size) {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
35 newq[i++] = queue[read++];
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
36 read &= mask;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
37 }
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
38 read = 0; write = i;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
39 calc_mask(size*2);
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
40 free(queue);
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
41 queue = newq;
651
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 649
diff changeset
42 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 649
diff changeset
43
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 649
diff changeset
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
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
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
026e9e7f1402 MailManager Fifo fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 647
diff changeset
48 write &= mask;
1189
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
49 if (write==read) {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
50 extend();
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
51 }
50
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
52 }
7927e00fb8e2 *** empty log message ***
gongo
parents:
diff changeset
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
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
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
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
61 } else {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
62 data = 0;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents: 1187
diff changeset
63 }
647
7ba4ad4538b1 MailManager rewrite. not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 644
diff changeset
64 return data;
643
2a611e8d8788 minor fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 640
diff changeset
65 }
2a611e8d8788 minor fix.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 640
diff changeset
66
640
ecf056ddd21a SimpeTask on Cell worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 603
diff changeset
67 /* end */