view paper/src/createCPUWorker.cbc @ 19:046b2b20d6c7 default tip

fix
author ryokka
date Mon, 09 Mar 2020 11:25:49 +0900
parents c7acb9211784
children
line wrap: on
line source

Worker* createCPUWorker(struct Context* context, int id, Queue* queue) {
    struct Worker* worker = new Worker();
    struct CPUWorker* cpuWorker = new CPUWorker();
    worker->worker = (union Data*)cpuWorker;
    worker->tasks = queue;
    cpuWorker->id = id;
    cpuWorker->loopCounter = 0;
    worker->taskReceive = C_taskReceiveCPUWorker;
    worker->shutdown = C_shutdownCPUWorker;
    pthread_create(&worker->thread, NULL, (void*)&startWorker, worker);
    return worker;
}

static void startWorker(struct Worker* worker) {
    struct CPUWorker* cpuWorker = &worker->worker->CPUWorker;
    cpuWorker->context = NEW(struct Context);
    initContext(cpuWorker->context);
    Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker;
    Gearef(cpuWorker->context, Worker)->tasks = worker->tasks;
    goto meta(cpuWorker->context, worker->taskReceive);
}