Mercurial > hg > Game > Cerium
diff 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 |
line wrap: on
line diff
--- a/TaskManager/kernel/ppe/MailManager.cc Thu Jul 07 13:50:56 2011 +0900 +++ b/TaskManager/kernel/ppe/MailManager.cc Fri Jul 08 18:34:18 2011 +0900 @@ -16,48 +16,51 @@ read = write = 0; calc_mask(qsize); queue = Newq(memaddr,size); +} - queue_remain = new Sem(size-1); //queue内に入る残りの数 - queue_count = new Sem(0); //queue内に現在入っている数 +MailManager::~MailManager() { free(queue); } +int +MailManager::count() +{ + return (write+size-read)&mask; } -MailManager::~MailManager() +void +MailManager::extend() { - free(queue); - delete queue_remain; - delete queue_count; -} - -int -MailManager::count() -{ - return queue_count->count(); + memaddr *newq = Newq(memaddr,size*2); + unsigned int i = 0; + while(i<size) { + newq[i++] = queue[read++]; + read &= mask; + } + read = 0; write = i; + calc_mask(size*2); + free(queue); + queue = newq; } void MailManager::send(memaddr data) { - queue_remain->sem_p(); //資源-1 - queue[write++] = data; - //maskの範囲を超えた場合、0に戻す write &= mask; - - queue_count->sem_v(); //資源+1 + if (write==read) { + extend(); + } } memaddr MailManager::recv() { - queue_count->sem_p(); //資源-1 - memaddr data; + if (count()>0) { data = queue[read++]; read &= mask; - - queue_remain->sem_v(); //資源+1 - + } else { + data = 0; + } return data; }