Mercurial > hg > Game > Cerium
diff TaskManager/kernel/ppe/CpuThreads.cc @ 1181:fa380908f801 draft
succcess to run parallel task manager
author | Daichi TOMA |
---|---|
date | Mon, 27 Jun 2011 03:03:55 +0900 |
parents | 5393bebe0956 |
children | 5a9bee9cc8c9 |
line wrap: on
line diff
--- a/TaskManager/kernel/ppe/CpuThreads.cc Sat Jun 25 09:39:45 2011 +0900 +++ b/TaskManager/kernel/ppe/CpuThreads.cc Mon Jun 27 03:03:55 2011 +0900 @@ -10,7 +10,18 @@ //SchedExternTask(StartProfile); -CpuThreads::CpuThreads(int num, int start_id) : cpu_num(num), id_offset(start_id) {} +CpuThreads::CpuThreads(int num, int start_id) : cpu_num(num), id_offset(start_id) { + + threads = new pthread_t[cpu_num]; + args = new cpu_thread_arg_t[cpu_num]; + + for (int i = 0; i < cpu_num; i++) { + args[i].cpuid = i + id_offset; + args[i].scheduler = new MainScheduler(); + args[i].run = 0; + } + +} CpuThreads::~CpuThreads() { @@ -22,7 +33,6 @@ for (int i = 0; i < cpu_num; i++) { pthread_join(threads[i], NULL); - sem_destroy(&sem[i]); } for (int i = 0; i < cpu_num; i++) { @@ -31,7 +41,6 @@ delete [] threads; delete [] args; - delete [] sem; } void * @@ -49,6 +58,8 @@ //SchedRegister(ShowTime); //SchedRegister(StartProfile); + argt->run = 1; + c_scheduler->run(new SchedNop()); c_scheduler->finish(); @@ -59,19 +70,14 @@ //CpuThreads::init() CpuThreads::init() { - 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; - args[i].scheduler = new MainScheduler(); + pthread_create(&threads[i], NULL, + &cpu_thread_run, (void*)&args[i]); } 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); + while (args[i].run == 0){ + } } } @@ -87,19 +93,18 @@ CpuThreads::get_mail(int cpuid, int count, memaddr *ret) { // need synchronization - sem_wait(&sem[cpuid]); *ret = args[cpuid-id_offset].scheduler->mail_read_from_host(); - sem_post(&sem[cpuid]); return 1; } int CpuThreads::has_mail(int cpuid, int count, memaddr *ret) { - // need synchronization - sem_wait(&sem[cpuid]); - return args[cpuid-id_offset].scheduler->has_mail_from_host(); - sem_post(&sem[cpuid]); + if (args[cpuid-id_offset].scheduler->has_mail_from_host() != 0) { + return get_mail(cpuid,count,ret); + } else { + return 0; //mailがないとき0を返す + } } /** @@ -118,12 +123,8 @@ */ void CpuThreads::send_mail(int cpuid, int num, memaddr *data) - { - // need synchronization - sem_wait(&sem[cpuid]); args[cpuid-id_offset].scheduler->mail_write_from_host(*data); - sem_post(&sem[cpuid]); } void