Mercurial > hg > Gears > GearsAgda
comparison src/parallel_execution/worker.c @ 236:865179a0a56d
fix taskManager
author | ikkun |
---|---|
date | Mon, 23 Jan 2017 20:00:46 +0900 |
parents | 05e61405cc88 |
children | 6f6cc49213c5 |
comparison
equal
deleted
inserted
replaced
235:05e61405cc88 | 236:865179a0a56d |
---|---|
3 #include "context.h" | 3 #include "context.h" |
4 #include "origin_cs.h" | 4 #include "origin_cs.h" |
5 | 5 |
6 static void start_worker(Worker* worker); | 6 static void start_worker(Worker* worker); |
7 | 7 |
8 union Data* createCPUWorker(struct Context* context, int id, Queue* queue, enum Code next) { | 8 union Data* createCPUWorker(struct Context* context, int id, Queue* queue) { |
9 struct Worker* worker = ALLOC(context, Worker); | 9 struct Worker* worker = ALLOC(context, Worker); |
10 struct CPUWorker* cpuWorker = ALLOC(context, CPUWorker); | 10 struct CPUWorker* cpuWorker = ALLOC(context, CPUWorker); |
11 worker->worker = (union Data*)cpuWorker; | 11 worker->worker = (union Data*)cpuWorker; |
12 cpuWorker->tasks = queue; | 12 cpuWorker->tasks = queue; |
13 cpuWorker->id = id; | 13 cpuWorker->id = id; |
14 cpuWorker->runFlag = 1; | |
15 cpuWorker->next = next; | |
16 worker->taskReceive = C_taskReceiveWorker; | 14 worker->taskReceive = C_taskReceiveWorker; |
17 worker->shutdown = C_shutdownWorker; | 15 worker->shutdown = C_shutdownWorker; |
18 pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker); | 16 pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker); |
19 return (union Data*)(worker); | 17 return (union Data*)(worker); |
20 } | 18 } |
25 initContext(cpuWorker->context); | 23 initContext(cpuWorker->context); |
26 goto meta(cpuWorker->context, C_taskReceiveWorker); | 24 goto meta(cpuWorker->context, C_taskReceiveWorker); |
27 } | 25 } |
28 | 26 |
29 __code taskReceiveWorker(struct Context* context, CPUWorker* worker) { | 27 __code taskReceiveWorker(struct Context* context, CPUWorker* worker) { |
30 if (! worker->runFlag) | |
31 return; // end thread | |
32 Queue* queue = worker->tasks; | 28 Queue* queue = worker->tasks; |
33 queue->next = C_getTask1; | 29 queue->next = C_getTask1; |
34 goto meta(context, queue->take); | 30 goto meta(context, queue->take); |
35 } | 31 } |
36 | 32 |
38 CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker); | 34 CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker); |
39 goto taskReceiveWorker(context,worker); | 35 goto taskReceiveWorker(context,worker); |
40 } | 36 } |
41 | 37 |
42 __code getTask1(struct Context* context, Worker* worker, struct Context* task) { | 38 __code getTask1(struct Context* context, Worker* worker, struct Context* task) { |
39 if (! task) | |
40 return; // end thread | |
43 task->worker = worker; | 41 task->worker = worker; |
44 goto meta(task, task->next); | 42 goto meta(task, task->next); |
45 } | 43 } |
46 | 44 |
47 __code getTask1_stub(struct Context* context) { | 45 __code getTask1_stub(struct Context* context) { |