Mercurial > hg > Members > Moririn
diff src/parallel_execution/worker.c @ 233:06133afb3b5b
create worker start_code
author | mir3636 |
---|---|
date | Sun, 22 Jan 2017 20:02:21 +0900 |
parents | 123b0d277b84 |
children | 05e61405cc88 |
line wrap: on
line diff
--- a/src/parallel_execution/worker.c Sun Jan 22 19:02:12 2017 +0900 +++ b/src/parallel_execution/worker.c Sun Jan 22 20:02:21 2017 +0900 @@ -3,9 +3,11 @@ #include "context.h" #include "origin_cs.h" +static void start_code(Worker* worker); + union Data* createCPUWorker(struct Context* context, int id, Queue* queue, enum Code next) { - struct Worker* worker = &ALLOCATE(context, Worker)->Worker; - struct CPUWorker* cpuWorker = &ALLOCATE(context, CPUWorker)->CPUWorker; + struct Worker* worker = ALLOC(context, Worker); + struct CPUWorker* cpuWorker = ALLOC(context, CPUWorker); worker->worker = (union Data*)cpuWorker; cpuWorker->tasks = queue; cpuWorker->id = id; @@ -13,12 +15,20 @@ cpuWorker->next = next; worker->taskReceive = C_taskReceiveWorker; worker->shutdown = C_shutdownWorker; + pthread_create(&worker->thread, NULL, (void*)&start_code, worker); return (union Data*)(worker); } +static void start_code(Worker* worker) { + CPUWorker* worker = (CPUWorker*)worker->worker; + worker->context = NEW(struct Context); + initContext(worker->context); + goto meta(worker->context, C_taskReceiveWorker); +} + __code taskReceiveWorker(struct Context* context, CPUWorker* worker) { if (! worker->runFlag) - goto meta(context, worker->next); + return; // end thread Queue* queue = worker->tasks; queue->next = C_getTask1; goto meta(context, queue->take);