annotate TaskManager/kernel/ppe/SemMailManager.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1189
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
1 #include <stdlib.h>
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
2 #include "SemMailManager.h"
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
3
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
4 void
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
5 SemMailManager::calc_mask(unsigned int qsize)
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
6 {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
7 mask = 1;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
8 while(qsize>mask) {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
9 mask <<= 1;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
10 }
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
11 size = mask;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
12 mask--;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
13 }
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
14
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
15 SemMailManager::SemMailManager(unsigned int qsize) {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
16 read = write = 0;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
17 calc_mask(qsize);
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
18 queue = Newq(memaddr,size);
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
19
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
20 queue_remain = new Sem(size-1); //queue内に入る残りの数
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
21 queue_count = new Sem(0); //queue内に現在入っている数
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
22
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
23 }
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
24
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
25 SemMailManager::~SemMailManager()
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
26 {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
27 free(queue);
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
28 delete queue_remain;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
29 delete queue_count;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
30 }
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
31
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
32 int
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
33 SemMailManager::count()
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
34 {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
35 return queue_count->count();
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
36 }
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
37
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
38 void
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
39 SemMailManager::send(memaddr data)
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
40 {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
41 queue_remain->sem_p(); //資源-1
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
42
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
43 queue[write++] = data;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
44 //maskの範囲を超えた場合、0に戻す
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
45 write &= mask;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
46
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
47 queue_count->sem_v(); //資源+1
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
48 }
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
49
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
50 memaddr
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
51 SemMailManager::recv()
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
52 {
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
53 queue_count->sem_p(); //資源-1
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
54
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
55 memaddr data;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
56 data = queue[read++];
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
57 read &= mask;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
58
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
59 queue_remain->sem_v(); //資源+1
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
60
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
61 return data;
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
62 }
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
63
898fdcf53c31 add SemMailManager
Daichi TOMA
parents:
diff changeset
64 /* end */