Mercurial > hg > GearsTemplate
view src/parallel_execution/CPUWorker.cbc @ 278:23767f714f4a
fix generate_stub
author | mir3636 |
---|---|
date | Thu, 02 Feb 2017 20:27:56 +0900 |
parents | 9d671e63df74 |
children | 2c2e4e597eb0 |
line wrap: on
line source
#include <libkern/OSAtomic.h> #include "../context.h" static void start_worker(Worker* worker); Worker* createCPUWorker(struct Context* context, int id, Queue* queue, enum Code next) { struct Worker* worker = new Worker(); struct CPUWorker* cpuWorker = new CPUWorker(); worker->worker = (union Data*)cpuWorker; worker->tasks = queue; cpuWorker->id = id; worker->taskReceive = C_taskReceiveWorker; worker->shutdown = C_shutdownWorker; pthread_create(&worker->worker->CPUWorker.thread, NULL, (void*)&start_worker, worker); return worker; } static void start_worker(Worker* worker) { CPUWorker* cpuWorker = (CPUWorker*)worker->worker; cpuWorker->context = NEW(struct Context); initContext(cpuWorker->context); Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker; goto meta(cpuWorker->context, C_taskReceiveWorker); } __code taskReceiveWorker(struct Worker* worker,struct Queue* queue) { queue->queue = (union Data*)worker->tasks; queue->next = C_getTask; goto meta(context, worker->tasks->take); } __code taskReceiveWorker_stub(struct Context* context) { CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker); pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex); goto taskReceiveWorker(context, &Gearef(context, Worker)->worker->Worker, Gearef(context, Queue)); } __code getTask(struct Worker* worker, struct Context* task) { if (!task) return; // end thread task->worker = worker; context->next = C_taskReceiveWorker; // set CG after task exec goto meta(task, task->next); } __code getTask_stub(struct Context* context) { Worker* worker = &Gearef(context,Worker)->worker->Worker; struct Context* task = &Gearef(context, Queue)->data->Context; goto getTask(context, worker, task); } #ifdef USE_CUDA __code twiceGpu() { cuMemcpyHtoDAsync(context,context,context,context->stream); cuLaunchkanel(); cuMemcpyDtoHAsync(); } #endif __code shutdownWorker(struct CPUWorker* worker) { }