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