Mercurial > hg > GearsTemplate
view src/parallel_execution/worker.c @ 248:1ede5390cda2
Fix segmentation fault but not multi thread running
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 25 Jan 2017 16:55:53 +0900 |
parents | ce262b2c1daf |
children | cd3486e4ba70 |
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); Gearef(cpuWorker->context, Worker)->worker = (union Data*)worker; goto meta(cpuWorker->context, C_taskReceiveWorker); } __code taskReceiveWorker(struct Context* context, Worker* worker, 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 Context* context, 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; Context* task = &Gearef(context, Queue)->data->context; goto getTask(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); }