Mercurial > hg > Members > Moririn
annotate 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 |
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 |
233 | 6 static void start_code(Worker* worker); |
7 | |
232 | 8 union Data* createCPUWorker(struct Context* context, int id, Queue* queue, enum Code next) { |
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; | |
14 cpuWorker->runFlag = 1; | |
15 cpuWorker->next = next; | |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
16 worker->taskReceive = C_taskReceiveWorker; |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
17 worker->shutdown = C_shutdownWorker; |
233 | 18 pthread_create(&worker->thread, NULL, (void*)&start_code, worker); |
183 | 19 return (union Data*)(worker); |
20 } | |
21 | |
233 | 22 static void start_code(Worker* worker) { |
23 CPUWorker* worker = (CPUWorker*)worker->worker; | |
24 worker->context = NEW(struct Context); | |
25 initContext(worker->context); | |
26 goto meta(worker->context, C_taskReceiveWorker); | |
27 } | |
28 | |
232 | 29 __code taskReceiveWorker(struct Context* context, CPUWorker* worker) { |
230 | 30 if (! worker->runFlag) |
233 | 31 return; // end thread |
230 | 32 Queue* queue = worker->tasks; |
227 | 33 queue->next = C_getTask1; |
34 goto meta(context, queue->take); | |
35 } | |
36 | |
37 __code taskReceiveWorker_stub(struct Context* context) { | |
232 | 38 CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker); |
230 | 39 goto taskReceiveWorker(context,worker); |
222
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
40 } |
77faa28128b4
Add taskSend for TaskManager
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
217
diff
changeset
|
41 |
230 | 42 __code getTask1(struct Context* context, Worker* worker, struct Context* task) { |
43 task->worker = worker; | |
44 goto meta(task, task->next); | |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
45 } |
109
059b26a250cc
Change put_queue process
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
46 |
169
ea7b11f3e717
Using Queue Interface
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
47 __code getTask1_stub(struct Context* context) { |
230 | 48 Worker* worker = Gearef(context,Worker); |
232 | 49 CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker); |
50 Context* task = &cpuWorker->tasks->data->context; | |
230 | 51 goto getTask1(context,worker,task); |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 } |
101 | 53 |
54 #ifdef USE_CUDA | |
98 | 55 __code twiceGpu(struct Context* context) { |
56 cuMemcpyHtoDAsync(context,context,context,context->stream); | |
57 cuLaunchkanel(); | |
58 cuMemcpyDtoHAsync(); | |
59 } | |
101 | 60 #endif |
227 | 61 |
232 | 62 __code shutdownWorker(struct Context* context, CPUWorker* worker) { |
230 | 63 worker->runFlag = 0; |
64 } | |
227 | 65 |
230 | 66 __code shutdownWorker_stub(struct Context* context) { |
232 | 67 CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker); |
230 | 68 goto shutdownWorker(context,worker); |
227 | 69 } |