view paper/src/createCPUWorker.cbc @ 2:c7acb9211784

add code, figure. and paper fix content
author ryokka
date Mon, 27 Jan 2020 20:41:36 +0900
parents
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);
}