Mercurial > hg > Game > Cerium
view TaskManager/kernel/ppe/SynchronizedMailManager.cc @ 1643:6c0b6947c231 draft
fix fft
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 22 Jun 2013 18:10:55 +0900 |
parents | 27e35b4098a4 |
children | f73ca57cdc81 |
line wrap: on
line source
#include <stdlib.h> #include "SynchronizedMailManager.h" void SynchronizedMailManager::calc_mask(unsigned int qsize) { mask = 1; while(qsize>mask) { mask <<= 1; } size = mask; mask--; } SynchronizedMailManager::SynchronizedMailManager(unsigned int qsize) { read = write = 0; calc_mask(qsize); queue = Newq(memaddr,size); queue_remain = new Sem(size-1); //queue内に入る残りの数 queue_count = new Sem(0); //queue内に現在入っている数 } SynchronizedMailManager::~SynchronizedMailManager() { free(queue); delete queue_remain; delete queue_count; } int SynchronizedMailManager::count() { return queue_count->count(); } void SynchronizedMailManager::send(memaddr data) { queue_remain->sem_p(); //資源-1 queue[write++] = data; //maskの範囲を超えた場合、0に戻す write &= mask; queue_count->sem_v(); //資源+1 } memaddr SynchronizedMailManager::recv() { queue_count->sem_p(); //資源-1 memaddr data; data = queue[read++]; read &= mask; queue_remain->sem_v(); //資源+1 return data; } /* end */