Mercurial > hg > Members > Moririn
annotate src/parallel_execution/CPUWorker.cbc @ 313:4addbc7469ee
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 15 Feb 2017 11:36:10 +0900 |
parents | ec0a5b4fba05 |
children | 7d664be4efa5 |
rev | line source |
---|---|
272 | 1 #include <libkern/OSAtomic.h> |
2 | |
278 | 3 #include "../context.h" |
272 | 4 |
5 static void start_worker(Worker* worker); | |
6 | |
280 | 7 Worker* createCPUWorker(struct Context* context, int id, Queue* queue) { |
272 | 8 struct Worker* worker = new Worker(); |
9 struct CPUWorker* cpuWorker = new CPUWorker(); | |
10 worker->worker = (union Data*)cpuWorker; | |
11 worker->tasks = queue; | |
12 cpuWorker->id = id; | |
13 worker->taskReceive = C_taskReceiveWorker; | |
14 worker->shutdown = C_shutdownWorker; | |
15 pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker); | |
16 return worker; | |
17 } | |
18 | |
19 static void start_worker(Worker* worker) { | |
20 CPUWorker* cpuWorker = (CPUWorker*)worker->worker; | |
21 cpuWorker->context = NEW(struct Context); | |
22 initContext(cpuWorker->context); | |
23 Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker; | |
282
a3448b0f0a56
Add input data gear
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
24 goto meta(cpuWorker->context, worker->taskReceive); |
272 | 25 } |
26 | |
27 __code taskReceiveWorker(struct Worker* worker,struct Queue* queue) { | |
28 queue->queue = (union Data*)worker->tasks; | |
29 queue->next = C_getTask; | |
30 goto meta(context, worker->tasks->take); | |
31 } | |
32 | |
33 __code taskReceiveWorker_stub(struct Context* context) { | |
34 goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue)); | |
35 } | |
36 | |
37 __code getTask(struct Worker* worker, struct Context* task) { | |
38 if (!task) | |
39 return; // end thread | |
40 task->worker = worker; | |
289 | 41 enum Code taskCg = task->next; |
288 | 42 task->next = C_odgCommit; // set CG after task exec |
289 | 43 goto meta(task, taskCg); |
272 | 44 } |
45 | |
46 __code getTask_stub(struct Context* context) { | |
47 Worker* worker = &Gearef(context,Worker)->worker->Worker; | |
48 struct Context* task = &Gearef(context, Queue)->data->Context; | |
49 goto getTask(context, worker, task); | |
50 } | |
51 | |
288 | 52 __code odgCommit(struct LoopCounter* loopCounter, struct Queue* queue, struct Context* task) { |
53 int i = loopCounter->i ; | |
54 if(task->odg + i < task->maxOdg) { | |
55 queue->queue = (union Data*)GET_WAIT_LIST(task->data[task->odg+i]); | |
56 queue->next = C_odgCommit1; | |
57 goto meta(context, queue->queue->Queue.take); | |
58 } | |
59 loopCounter->i = 0; | |
60 goto meta(context, C_taskReceiveWorker); | |
61 } | |
62 | |
63 __code odgCommit_stub(struct Context* context) { | |
64 struct Context* workerContext = context->worker->worker->CPUWorker.context; | |
65 goto odgCommit(workerContext, | |
66 Gearef(workerContext, LoopCounter), | |
67 Gearef(workerContext, Queue), | |
68 context); | |
69 } | |
70 | |
71 __code odgCommit1(struct TaskManager* taskManager, struct Context* task) { | |
72 if(__sync_fetch_and_sub(&task->idgCount, 1)) { | |
73 if(task->idgCount == 0) { | |
74 taskManager->taskManager = (union Data*)task->taskManager; | |
75 taskManager->context = task; | |
76 taskManager->next = C_odgCommit; | |
77 goto meta(context, task->taskManager->spawn); | |
78 } | |
79 } else { | |
80 goto meta(context, C_odgCommit1); | |
81 } | |
82 } | |
83 | |
84 __code odgCommit1_stub(struct Context* context) { | |
85 struct Context* task = &Gearef(context, Queue)->data->Context; | |
86 goto odgCommit1(context, | |
87 Gearef(context, TaskManager), | |
88 task); | |
89 | |
90 } | |
91 | |
272 | 92 __code shutdownWorker(struct CPUWorker* worker) { |
93 } |