Mercurial > hg > Game > Cerium
changeset 1181:fa380908f801 draft
succcess to run parallel task manager
author | Daichi TOMA |
---|---|
date | Mon, 27 Jun 2011 03:03:55 +0900 |
parents | 2e20d2bb55c6 |
children | 5a9bee9cc8c9 |
files | TaskManager/Cell/CellTaskManagerImpl.h TaskManager/kernel/ppe/CpuThreads.cc TaskManager/kernel/ppe/CpuThreads.h |
diffstat | 3 files changed, 25 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Cell/CellTaskManagerImpl.h Sat Jun 25 09:39:45 2011 +0900 +++ b/TaskManager/Cell/CellTaskManagerImpl.h Mon Jun 27 03:03:55 2011 +0900 @@ -8,7 +8,7 @@ class CellTaskManagerImpl : public TaskManagerImpl { public: /* constructor */ - CellTaskManagerImpl(int num, CpuThreads *cpus) : TaskManagerImpl(num) {} + CellTaskManagerImpl(int num, CpuThreads *cpus) : TaskManagerImpl(num) {speThreads = cpus;} ~CellTaskManagerImpl(); /* variables */
--- 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
--- a/TaskManager/kernel/ppe/CpuThreads.h Sat Jun 25 09:39:45 2011 +0900 +++ b/TaskManager/kernel/ppe/CpuThreads.h Mon Jun 27 03:03:55 2011 +0900 @@ -2,7 +2,6 @@ #define INCLUDED_CPU_THREADS #include <pthread.h> -#include <semaphore.h> #include "Threads.h" #include "TaskManagerImpl.h" #include "MainScheduler.h" @@ -12,6 +11,7 @@ // should be syncrhonized MainScheduler *scheduler; TaskManagerImpl *manager; + int run; } cpu_thread_arg_t; class CpuThreads : Threads { @@ -32,7 +32,6 @@ /* variables */ pthread_t *threads; cpu_thread_arg_t *args; - sem_t *sem; int cpu_num; int id_offset; };