Mercurial > hg > Game > Cerium
diff TaskManager/kernel/ppe/MailManager.cc @ 1180:2e20d2bb55c6 draft
change mailmanager to mail on semaphore
author | Daichi TOMA |
---|---|
date | Sat, 25 Jun 2011 09:39:45 +0900 |
parents | 08ed5e750d78 |
children | 4c209dd223cd |
line wrap: on
line diff
--- a/TaskManager/kernel/ppe/MailManager.cc Tue Jun 21 19:50:53 2011 +0900 +++ b/TaskManager/kernel/ppe/MailManager.cc Sat Jun 25 09:39:45 2011 +0900 @@ -16,9 +16,27 @@ read = write = 0; calc_mask(qsize); queue = Newq(memaddr,size); + + mutex_s = new pthread_mutex_t; //sendのロック用 + mutex_r = new pthread_mutex_t; //recvのロック用 + pthread_mutex_init(mutex_s, NULL); + pthread_mutex_init(mutex_r, NULL); + + remain = new Sem(0); //queue内のアイテム数を管理 + } -MailManager::~MailManager() { free(queue); } +MailManager::~MailManager() +{ + free(queue); + + pthread_mutex_destroy(mutex_s); + pthread_mutex_destroy(mutex_r); + + delete mutex_s; + delete mutex_r; + delete remain; +} int MailManager::count() @@ -44,16 +62,24 @@ void MailManager::send(memaddr data) { + pthread_mutex_lock(mutex_s); + queue[write++] = data; write &= mask; if (write==read) { extend(); } + + pthread_mutex_unlock(mutex_s); + remain->sem_v(); //資源を解放 } memaddr MailManager::recv() { + pthread_mutex_lock(mutex_r); + + remain->sem_p(); //資源の確保 memaddr data; if (count()>0) { data = queue[read++]; @@ -61,6 +87,8 @@ } else { data = 0; } + pthread_mutex_unlock(mutex_r); + return data; }