# HG changeset patch # User Daichi TOMA # Date 1307616077 -32400 # Node ID 730f5e5c83512de530b2cfde3dde5e108eb0c2e5 # Parent fc4a96198ed38ac2f6f8cd82c9f0f006272540e4 fix syncronized queue diff -r fc4a96198ed3 -r 730f5e5c8351 TaskManager/kernel/ppe/CpuThreads.cc --- 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]); } diff -r fc4a96198ed3 -r 730f5e5c8351 TaskManager/kernel/ppe/CpuThreads.h --- a/TaskManager/kernel/ppe/CpuThreads.h Tue Jun 07 18:07:57 2011 +0900 +++ b/TaskManager/kernel/ppe/CpuThreads.h Thu Jun 09 19:41:17 2011 +0900 @@ -31,9 +31,9 @@ /* variables */ pthread_t *threads; cpu_thread_arg_t *args; + sem_t *sem; int cpu_num; int id_offset; - sem_t sem; }; #endif