Mercurial > hg > GearsTemplate
diff src/parallel_execution/taskManager.c @ 219:de1ba77f94b4
Rename TaskManager.c
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 09 Jan 2017 05:58:46 +0900 |
parents | src/parallel_execution/TaskManager.c@d8a59b727f65 |
children | 6c0692c9bfed |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/taskManager.c Mon Jan 09 05:58:46 2017 +0900 @@ -0,0 +1,59 @@ +#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; + taskManagerImpl -> activeQueue = (struct Queue*)createSynchronizedQueue(context); + taskManagerImpl -> taskQueue = (struct Queue*)createSynchronizedQueue(context); + 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, + (struct TaskManagerImpl *)context->data[D_TaskManager]->TaskManager.taskManager->TaskManager.taskManager, + &context->data[D_Queue]->Queue, + context->data[D_TaskManager]->TaskManager.task, + context->data[D_TaskManager]->TaskManager.next + ); +} + +__code shutdownTaskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { + int i = loopCounter->i; + + if (i < worker->id) { + pthread_join(worker->contexts[i].thread, NULL); + loopCounter->i++; + + goto meta(context, C_taskManager); + } + + loopCounter->i = 0; + + Time *t = &context->data[D_Time]->Time; + t->next = C_code2; + goto meta(context, C_end_time); +} + +__code shutdownTaskManager_stub(struct Context* context) { + goto shutdownTaskManager(context, &context->data[D_LoopCounter]->LoopCounter, &context->data[D_Worker]->Worker); +}