annotate prepaper/src/createCPUWorker.cbc @ 14:a63df15c9afc default tip

DONE
author soto <soto@cr.ie.u-ryukyu.ac.jp>
date Mon, 15 Feb 2021 23:36:39 +0900
parents 3dba680da508
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3dba680da508 init-test
soto
parents:
diff changeset
1 Worker* createCPUWorker(struct Context* context, int id, Queue* queue) {
3dba680da508 init-test
soto
parents:
diff changeset
2 struct Worker* worker = new Worker();
3dba680da508 init-test
soto
parents:
diff changeset
3 struct CPUWorker* cpuWorker = new CPUWorker();
3dba680da508 init-test
soto
parents:
diff changeset
4 worker->worker = (union Data*)cpuWorker;
3dba680da508 init-test
soto
parents:
diff changeset
5 worker->tasks = queue;
3dba680da508 init-test
soto
parents:
diff changeset
6 cpuWorker->id = id;
3dba680da508 init-test
soto
parents:
diff changeset
7 cpuWorker->loopCounter = 0;
3dba680da508 init-test
soto
parents:
diff changeset
8 worker->taskReceive = C_taskReceiveCPUWorker;
3dba680da508 init-test
soto
parents:
diff changeset
9 worker->shutdown = C_shutdownCPUWorker;
3dba680da508 init-test
soto
parents:
diff changeset
10 pthread_create(&worker->thread, NULL, (void*)&startWorker, worker);
3dba680da508 init-test
soto
parents:
diff changeset
11 return worker;
3dba680da508 init-test
soto
parents:
diff changeset
12 }
3dba680da508 init-test
soto
parents:
diff changeset
13
3dba680da508 init-test
soto
parents:
diff changeset
14 static void startWorker(struct Worker* worker) {
3dba680da508 init-test
soto
parents:
diff changeset
15 struct CPUWorker* cpuWorker = &worker->worker->CPUWorker;
3dba680da508 init-test
soto
parents:
diff changeset
16 cpuWorker->context = NEW(struct Context);
3dba680da508 init-test
soto
parents:
diff changeset
17 initContext(cpuWorker->context);
3dba680da508 init-test
soto
parents:
diff changeset
18 Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker;
3dba680da508 init-test
soto
parents:
diff changeset
19 Gearef(cpuWorker->context, Worker)->tasks = worker->tasks;
3dba680da508 init-test
soto
parents:
diff changeset
20 goto meta(cpuWorker->context, worker->taskReceive);
3dba680da508 init-test
soto
parents:
diff changeset
21 }