comparison 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
comparison
equal deleted inserted replaced
218:d8a59b727f65 219:de1ba77f94b4
1 #include "context.h"
2 #include "stack.h"
3 #include "queue.h"
4 #include "origin_cs.h"
5 #include <stdio.h>
6
7 union Data* createTaskManager(struct Context* context) {
8 struct TaskManager* taskManager = &ALLOCATE(context, TaskManager)->TaskManager;
9 struct TaskManagerImpl* taskManagerImpl = &ALLOCATE(context, TaskManagerImpl)->TaskManagerImpl;
10 taskManagerImpl -> activeQueue = (struct Queue*)createSynchronizedQueue(context);
11 taskManagerImpl -> taskQueue = (struct Queue*)createSynchronizedQueue(context);
12 taskManager->spawn = C_spawnTaskManager;
13 taskManager->shutdown = C_shutdownTaskManager;
14 // taskManager->deadLockDetected = C_deadLockDetected;
15 return (union Data*)(taskManager);
16 }
17
18 __code spawnTaskManager(struct Context* context, struct TaskManagerImpl* taskManager, struct Queue* queue, struct Task* task, enum Code next) {
19 if (task->idsCount == 0) {
20 // enqueue activeQueue
21 queue->queue = (union Data*)taskManager->activeQueue;
22 } else {
23 // enqueue waitQueue
24 queue->queue = (union Data*)taskManager->taskQueue;
25 }
26 queue->data = (union Data*)task;
27 queue->next = next;
28 goto meta(context, queue->queue->Queue.put);
29 }
30
31 __code spawnTaskManager_stub(struct Context* context) {
32 goto spawnTaskManager(context,
33 (struct TaskManagerImpl *)context->data[D_TaskManager]->TaskManager.taskManager->TaskManager.taskManager,
34 &context->data[D_Queue]->Queue,
35 context->data[D_TaskManager]->TaskManager.task,
36 context->data[D_TaskManager]->TaskManager.next
37 );
38 }
39
40 __code shutdownTaskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) {
41 int i = loopCounter->i;
42
43 if (i < worker->id) {
44 pthread_join(worker->contexts[i].thread, NULL);
45 loopCounter->i++;
46
47 goto meta(context, C_taskManager);
48 }
49
50 loopCounter->i = 0;
51
52 Time *t = &context->data[D_Time]->Time;
53 t->next = C_code2;
54 goto meta(context, C_end_time);
55 }
56
57 __code shutdownTaskManager_stub(struct Context* context) {
58 goto shutdownTaskManager(context, &context->data[D_LoopCounter]->LoopCounter, &context->data[D_Worker]->Worker);
59 }