178
|
1 #include "context.h"
|
|
2 #include "stack.h"
|
182
|
3 #include "queue.h"
|
178
|
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 TaskManager* taskManagerImpl = &ALLOCATE(context, TaskManagerImpl)->taskManagerImpl;
|
182
|
10 taskManagerImpl -> activeQueue = createSynchronizedQueue(context);
|
|
11 taskManagerImpl -> waitQueue = createSynchronizedQueue(context);
|
|
12 taskManager->taskManager = (union Data*)taskManagerImpl;
|
178
|
13 taskManager->spawn = C_spawnTaskManager;
|
|
14 taskManager->shutdown = C_shutdownTaskManager;
|
|
15 return (union Data*)(taskManager);
|
|
16 }
|
|
17
|
|
18 __code spawnTaskManager(struct Context* context, struct Task* task, struct Element* element, struct Queue* queue, struct Queue* activeQueue, struct Queue* waitQueue) {
|
|
19 if (task->idsCount == 0) {
|
|
20 // enqueue activeQueue
|
|
21 queue->queue = (union Data*)activeQueue;
|
|
22 } else {
|
|
23 // enqueue waitQueue
|
|
24 queue->queue = (union Data*)waitQueue;
|
|
25 }
|
|
26 queue->data = element->data;
|
|
27 queue->next = context->next;
|
|
28 goto meta(context, queue->queue->put);
|
|
29 }
|
|
30
|
|
31 __code spawnTaskManager_stub(struct Context* context) {
|
|
32 goto spawnTask(context,
|
|
33 context->data[D_Element]->element.data,
|
|
34 &context->data[D_Element]->element,
|
|
35 &context->data[D_ActiveQueue]->Queue,
|
|
36 &context->data[D_WaitQueue]->Queue);
|
|
37 }
|
|
38
|
182
|
39 __code shutdownTaskManager(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) {
|
178
|
40 int i = loopCounter->i;
|
|
41
|
|
42 if (i < worker->num) {
|
|
43 pthread_join(worker->contexts[i].thread, NULL);
|
|
44 loopCounter->i++;
|
|
45
|
|
46 goto meta(context, TaskManager);
|
|
47 }
|
|
48
|
|
49 loopCounter->i = 0;
|
|
50
|
|
51 Time *t = &context->data[D_Time]->Time;
|
|
52 t->next = C_code2;
|
|
53 goto meta(context, EndTime);
|
|
54 }
|
|
55
|
182
|
56 __code shutdownTaskManager_stub(struct Context* context) {
|
|
57 goto shutdownTaskManager(context, &context->data[D_LoopCounter]->loopCounter, &context->data[D_Worker]->worker);
|
178
|
58 }
|