Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/ppe/SynchronizedMailManager.cc @ 1546:61164c687b29 draft
fix GpuScheduler flip
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 05 Feb 2013 13:15:46 +0900 |
parents | 27e35b4098a4 |
children | 6c0b6947c231 |
rev | line source |
---|---|
1189 | 1 #include <stdlib.h> |
1196
27e35b4098a4
Rename MailManager
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1189
diff
changeset
|
2 #include "SynchronizedMailManager.h" |
1189 | 3 |
4 void | |
1196
27e35b4098a4
Rename MailManager
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1189
diff
changeset
|
5 SynchronizedMailManager::calc_mask(unsigned int qsize) |
1189 | 6 { |
7 mask = 1; | |
8 while(qsize>mask) { | |
9 mask <<= 1; | |
10 } | |
11 size = mask; | |
12 mask--; | |
13 } | |
14 | |
1196
27e35b4098a4
Rename MailManager
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1189
diff
changeset
|
15 SynchronizedMailManager::SynchronizedMailManager(unsigned int qsize) { |
1189 | 16 read = write = 0; |
17 calc_mask(qsize); | |
18 queue = Newq(memaddr,size); | |
19 | |
20 queue_remain = new Sem(size-1); //queue内に入る残りの数 | |
21 queue_count = new Sem(0); //queue内に現在入っている数 | |
22 | |
23 } | |
24 | |
1196
27e35b4098a4
Rename MailManager
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1189
diff
changeset
|
25 SynchronizedMailManager::~SynchronizedMailManager() |
1189 | 26 { |
27 free(queue); | |
28 delete queue_remain; | |
29 delete queue_count; | |
30 } | |
31 | |
32 int | |
1196
27e35b4098a4
Rename MailManager
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1189
diff
changeset
|
33 SynchronizedMailManager::count() |
1189 | 34 { |
35 return queue_count->count(); | |
36 } | |
37 | |
38 void | |
1196
27e35b4098a4
Rename MailManager
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1189
diff
changeset
|
39 SynchronizedMailManager::send(memaddr data) |
1189 | 40 { |
41 queue_remain->sem_p(); //資源-1 | |
42 | |
43 queue[write++] = data; | |
44 //maskの範囲を超えた場合、0に戻す | |
45 write &= mask; | |
46 | |
47 queue_count->sem_v(); //資源+1 | |
48 } | |
49 | |
50 memaddr | |
1196
27e35b4098a4
Rename MailManager
Daichi TOMA <e085740@ie.u-ryukyu.ac.jp>
parents:
1189
diff
changeset
|
51 SynchronizedMailManager::recv() |
1189 | 52 { |
53 queue_count->sem_p(); //資源-1 | |
54 | |
55 memaddr data; | |
56 data = queue[read++]; | |
57 read &= mask; | |
58 | |
59 queue_remain->sem_v(); //資源+1 | |
60 | |
61 return data; | |
62 } | |
63 | |
64 /* end */ |