Mercurial > hg > Members > Moririn
view src/parallel_execution/worker.c @ 242:9f3f8ed6ed9f
Add sendTask
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 24 Jan 2017 18:39:42 +0900 |
parents | 864bb372f37f |
children | d1567718f12c |
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; cpuWorker->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, CPUWorker* worker) { Queue* queue = worker->tasks; queue->next = C_getTask1; goto meta(context, queue->take); } __code taskReceiveWorker_stub(struct Context* context) { CPUWorker* worker = (CPUWorker *)GearImpl(context, Worker, worker); goto taskReceiveWorker(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); CPUWorker* cpuWorker = (CPUWorker *)GearImpl(context, Worker, worker); Context* task = &cpuWorker->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); }