Mercurial > hg > Gears > GearsAgda
view src/parallel_execution/taskManager.c @ 231:24da4f217447
fix
author | mir3636 |
---|---|
date | Sun, 22 Jan 2017 18:19:23 +0900 |
parents | a1fb3f2d1a36 |
children | 06133afb3b5b |
line wrap: on
line source
#include "context.h" #include "stack.h" #include "queue.h" #include "origin_cs.h" #include <stdio.h> union Data* createTaskManager(struct Context* context) { struct TaskManager* taskManager = &ALLOCATE(context, TaskManager)->TaskManager; struct TaskManagerImpl* taskManagerImpl = &ALLOCATE(context, TaskManagerImpl)->TaskManagerImpl; taskManager->taskManager = (union Data*)taskManagerImpl; taskManagerImpl -> activeQueue = &createSynchronizedQueue(context)->Queue; taskManagerImpl -> taskQueue = &createSynchronizedQueue(context)->Queue; taskManager->spawn = C_spawnTaskManager; taskManager->shutdown = C_shutdownTaskManager; // taskManager->deadLockDetected = C_deadLockDetected; return (union Data*)(taskManager); } __code spawnTaskManager(struct Context* context, struct TaskManagerImpl* taskManager, struct Queue* queue, struct Task* task, enum Code next) { if (task->idsCount == 0) { // enqueue activeQueue queue->queue = (union Data*)taskManager->activeQueue; } else { // enqueue waitQueue queue->queue = (union Data*)taskManager->taskQueue; } queue->data = (union Data*)task; queue->next = next; goto meta(context, queue->queue->Queue.put); } __code spawnTaskManager_stub(struct Context* context) { goto spawnTaskManager(context, &context->data[D_TaskManager]->TaskManager.taskManager->TaskManager.taskManager->TaskManagerImpl, &context->data[D_Queue]->Queue, context->data[D_TaskManager]->TaskManager.task, context->data[D_TaskManager]->TaskManager.next ); } __code taskSend(struct Context* context) { if(loopCounter->i < taskManager->numWorker) { taskManager->workers[i]->taskSend; loopCounter->i++; goto meta(context, C_taskSend); } goto meta(context, TaskManager->next); } __code createWorker1(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { int i = loopCounter->i; if (i < worker->id) { struct Context* worker_context = &worker->contexts[i]; worker_context->next = C_getTask1; worker_context->data[D_Tree] = context->data[D_Tree]; // worker_context->data[D_ActiveQueue] = context->data[D_ActiveQueue]; pthread_create(&worker_context->thread, NULL, (void*)&start_code, worker_context); worker_context->thread_num = i; loopCounter->i++; goto meta(context, C_createWorker1); } loopCounter->i = 0; goto meta(context, C_taskManager); } __code createWorker1_stub(struct Context* context) { goto createWorker1(context, &context->data[D_LoopCounter]->LoopCounter, &context->data[D_Worker]->Worker); } __code shutdownTaskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker, struct TaskManager* taskManager) { int i = loopCounter->i; if (i < worker->id) { pthread_join(worker->contexts[i].thread, NULL); loopCounter->i++; goto meta(context, C_shutdownTaskManager); } loopCounter->i = 0; goto meta(context, taskManager->next); } __code shutdownTaskManager_stub(struct Context* context) { goto shutdownTaskManager(context, &context->data[D_LoopCounter]->LoopCounter, &context->data[D_Worker]->Worker, Gearef(context, TaskManager)); }