0
|
1 Worker* createCPUWorker(struct Context* context, int id, Queue* queue) {
|
|
2 struct Worker* worker = new Worker();
|
|
3 struct CPUWorker* cpuWorker = new CPUWorker();
|
|
4 worker->worker = (union Data*)cpuWorker;
|
|
5 worker->tasks = queue;
|
|
6 cpuWorker->id = id;
|
|
7 cpuWorker->loopCounter = 0;
|
|
8 worker->taskReceive = C_taskReceiveCPUWorker;
|
|
9 worker->shutdown = C_shutdownCPUWorker;
|
|
10 pthread_create(&worker->thread, NULL, (void*)&startWorker, worker);
|
|
11 return worker;
|
|
12 }
|
|
13
|
|
14 static void startWorker(struct Worker* worker) {
|
|
15 struct CPUWorker* cpuWorker = &worker->worker->CPUWorker;
|
|
16 cpuWorker->context = NEW(struct Context);
|
|
17 initContext(cpuWorker->context);
|
|
18 Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker;
|
|
19 Gearef(cpuWorker->context, Worker)->tasks = worker->tasks;
|
|
20 goto meta(cpuWorker->context, worker->taskReceive);
|
|
21 }
|