Mercurial > hg > Game > Cerium
view TaskManager/kernel/ppe/SynchronizedMailManager.cc @ 2069:26aa08c9a1de draft default tip
cuda example fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 12 Feb 2017 10:04:55 +0900 (2017-02-12) |
parents | f73ca57cdc81 |
children |
line wrap: on
line source
#include <stdlib.h> #include "SynchronizedMailManager.h" void SynchronizedMailManager::set_waiter(SemPtr w) { ppe_waiter = w; } 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内に現在入っている数 ppe_waiter = 0; // not notify send message } 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 if (ppe_waiter) ppe_waiter->sem_v1(); // notyfy message send } memaddr SynchronizedMailManager::recv() { queue_count->sem_p(); //資源-1 memaddr data; data = queue[read++]; read &= mask; queue_remain->sem_v(); //資源+1 return data; } /* end */