Mercurial > hg > Game > Cerium
changeset 1177:730f5e5c8351 draft
fix syncronized queue
author | Daichi TOMA <amothic@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 09 Jun 2011 19:41:17 +0900 |
parents | fc4a96198ed3 |
children | cb8161fd0af1 2abd68a1ac2a |
files | TaskManager/kernel/ppe/CpuThreads.cc TaskManager/kernel/ppe/CpuThreads.h |
diffstat | 2 files changed, 13 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/kernel/ppe/CpuThreads.cc Tue Jun 07 18:07:57 2011 +0900 +++ b/TaskManager/kernel/ppe/CpuThreads.cc Thu Jun 09 19:41:17 2011 +0900 @@ -25,9 +25,7 @@ delete [] threads; delete [] args; - - /* セマフォ変数の破棄 */ - sem_destroy(&sem); + delete [] sem; } void * @@ -53,6 +51,7 @@ { threads = new pthread_t[cpu_num]; args = new cpu_thread_arg_t[cpu_num]; + sem = new sem_t[cpu_num]; for (int i = 0; i < cpu_num; i++) { args[i].cpuid = i + id_offset; @@ -62,12 +61,8 @@ for (int i = 0; i < cpu_num; i++) { pthread_create(&threads[i], NULL, &cpu_thread_run, (void*)&args[i]); + sem_init(&sem[i], 0, 1); } - /* セマフォ変数の定義 */ - sem_t sem; - - /* セマフォ変数の初期化 */ - sem_init(&sem, 0, 1); } /** @@ -82,9 +77,10 @@ CpuThreads::get_mail(int cpuid, int count, memaddr *ret) { // need synchronization - sem_wait(&sem); + int cpu = cpuid - 1; + sem_wait(&sem[cpu]); *ret = args[cpuid-id_offset].scheduler->mail_read_from_host(); - sem_post(&sem); + sem_post(&sem[cpu]); return 1; } @@ -92,9 +88,10 @@ CpuThreads::has_mail(int cpuid, int count, memaddr *ret) { // need synchronization - sem_wait(&sem); + int cpu = cpuid - 1; + sem_wait(&sem[cpu]); return args[cpuid-id_offset].scheduler->has_mail_from_host(); - sem_post(&sem); + sem_post(&sem[cpu]); } /** @@ -116,9 +113,10 @@ { // need synchronization - sem_wait(&sem); + int cpu = cpuid - 1; + sem_wait(&sem[cpu]); args[cpuid-id_offset].scheduler->mail_write_from_host(*data); - sem_post(&sem); + sem_post(&sem[cpu]); }