Mercurial > hg > Members > Moririn
annotate src/parallel_execution/worker.c @ 237:6f6cc49213c5
fix
author | mir3636 |
---|---|
date | Tue, 24 Jan 2017 09:19:58 +0900 |
parents | 865179a0a56d |
children | 864bb372f37f |
rev | line source |
---|---|
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <libkern/OSAtomic.h> |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 #include "context.h" |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #include "origin_cs.h" |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
235 | 6 static void start_worker(Worker* worker); |
233 | 7 |
236 | 8 union Data* createCPUWorker(struct Context* context, int id, Queue* queue) { |
233 | 9 struct Worker* worker = ALLOC(context, Worker); |
10 struct CPUWorker* cpuWorker = ALLOC(context, CPUWorker); | |
232 | 11 worker->worker = (union Data*)cpuWorker; |
12 cpuWorker->tasks = queue; | |
13 cpuWorker->id = id; | |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
14 worker->taskReceive = C_taskReceiveWorker; |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
15 worker->shutdown = C_shutdownWorker; |
235 | 16 pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker); |
183 | 17 return (union Data*)(worker); |
18 } | |
19 | |
235 | 20 static void start_worker(Worker* worker) { |
21 CPUWorker* cpuWorker = (CPUWorker*)worker->worker; | |
22 cpuWorker->context = NEW(struct Context); | |
23 initContext(cpuWorker->context); | |
24 goto meta(cpuWorker->context, C_taskReceiveWorker); | |
233 | 25 } |
26 | |
232 | 27 __code taskReceiveWorker(struct Context* context, CPUWorker* worker) { |
230 | 28 Queue* queue = worker->tasks; |
227 | 29 queue->next = C_getTask1; |
30 goto meta(context, queue->take); | |
31 } | |
32 | |
33 __code taskReceiveWorker_stub(struct Context* context) { | |
232 | 34 CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker); |
230 | 35 goto taskReceiveWorker(context,worker); |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
36 } |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
37 |
230 | 38 __code getTask1(struct Context* context, Worker* worker, struct Context* task) { |
236 | 39 if (! task) |
40 return; // end thread | |
230 | 41 task->worker = worker; |
42 goto meta(task, task->next); | |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
43 } |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
44 |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
45 __code getTask1_stub(struct Context* context) { |
230 | 46 Worker* worker = Gearef(context,Worker); |
232 | 47 CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker); |
48 Context* task = &cpuWorker->tasks->data->context; | |
230 | 49 goto getTask1(context,worker,task); |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 } |
101 | 51 |
52 #ifdef USE_CUDA | |
98 | 53 __code twiceGpu(struct Context* context) { |
54 cuMemcpyHtoDAsync(context,context,context,context->stream); | |
55 cuLaunchkanel(); | |
56 cuMemcpyDtoHAsync(); | |
57 } | |
101 | 58 #endif |
227 | 59 |
232 | 60 __code shutdownWorker(struct Context* context, CPUWorker* worker) { |
230 | 61 } |
227 | 62 |
230 | 63 __code shutdownWorker_stub(struct Context* context) { |
232 | 64 CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker); |
230 | 65 goto shutdownWorker(context,worker); |
227 | 66 } |