Mercurial > hg > Members > Moririn
view src/parallel_execution/worker.c @ 244:d1567718f12c
Fix error
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 25 Jan 2017 01:48:47 +0900 |
parents | 9f3f8ed6ed9f |
children | ce262b2c1daf |
line wrap: on
line source
#include <libkern/OSAtomic.h> #include "context.h" #include "origin_cs.h" static void start_worker(Worker* worker); union Data* createCPUWorker(struct Context* context, int id, Queue* queue) { struct Worker* worker = ALLOC(context, Worker); struct CPUWorker* cpuWorker = ALLOC(context, 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 (union Data*)(worker); } static void start_worker(Worker* worker) { CPUWorker* cpuWorker = (CPUWorker*)worker->worker; cpuWorker->context = NEW(struct Context); initContext(cpuWorker->context); pthread_cond_wait(&cpuWorker->cond, &cpuWorker->mutex); goto meta(cpuWorker->context, C_taskReceiveWorker); } __code taskReceiveWorker(struct Context* context, Worker* worker) { Queue* queue = worker->tasks; queue->next = C_getTask1; goto meta(context, queue->take); } __code taskReceiveWorker_stub(struct Context* context) { goto taskReceiveWorker(context, Gearef(context, Worker)); } __code getTask1(struct Context* context, Worker* worker, struct Context* task) { if (!task) return; // end thread task->worker = worker; goto meta(task, task->next); } __code getTask1_stub(struct Context* context) { Worker* worker = Gearef(context,Worker); Context* task = &worker->tasks->data->context; goto getTask1(context,worker,task); } #ifdef USE_CUDA __code twiceGpu(struct Context* context) { cuMemcpyHtoDAsync(context,context,context,context->stream); cuLaunchkanel(); cuMemcpyDtoHAsync(); } #endif __code shutdownWorker(struct Context* context, CPUWorker* worker) { } __code shutdownWorker_stub(struct Context* context) { CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker); goto shutdownWorker(context,worker); }