Mercurial > hg > Members > innparusu > Gears
annotate src/parallel_execution/context.c @ 95:3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 29 Jan 2016 05:36:52 +0900 |
parents | 851da1107223 |
children | 8987cf13d5bb |
rev | line source |
---|---|
86 | 1 #include <stdlib.h> |
2 | |
3 #include "context.h" | |
4 | |
5 extern __code code1_stub(struct Context*); | |
6 extern __code code2_stub(struct Context*); | |
7 extern __code code3_stub(struct Context*); | |
8 extern __code code4(struct Context*); | |
9 extern __code code5(struct Context*); | |
10 extern __code find(struct Context*); | |
11 extern __code not_find(struct Context*); | |
12 extern __code code6(struct Context*); | |
13 extern __code meta(struct Context*); | |
14 extern __code put_stub(struct Context*); | |
15 extern __code replaceNode_stub(struct Context*); | |
16 extern __code insertNode_stub(struct Context*); | |
17 extern __code rotateLeft_stub(struct Context*); | |
18 extern __code rotateRight_stub(struct Context*); | |
19 extern __code colorFlip_stub(struct Context*); | |
20 extern __code fixUp_stub(struct Context*); | |
21 extern __code changeReference_stub(struct Context*); | |
22 extern __code insert1_stub(struct Context*); | |
23 extern __code insert2_stub(struct Context*); | |
24 extern __code insert3_stub(struct Context*); | |
25 extern __code insert4_stub(struct Context*); | |
26 extern __code insert4_1_stub(struct Context*); | |
27 extern __code insert4_2_stub(struct Context*); | |
28 extern __code insert5_stub(struct Context*); | |
29 extern __code stackClear_stub(struct Context*); | |
30 extern __code get_stub(struct Context*); | |
31 extern __code search_stub(struct Context*); | |
32 extern __code delete_stub(struct Context*); | |
33 extern __code delete1_stub(struct Context*); | |
34 extern __code delete2_stub(struct Context*); | |
35 extern __code delete3_stub(struct Context*); | |
36 extern __code replaceNodeForDelete1_stub(struct Context*); | |
37 extern __code replaceNodeForDelete2_stub(struct Context*); | |
38 extern __code findMax1_stub(struct Context*); | |
39 extern __code findMax2_stub(struct Context*); | |
40 extern __code deleteCase1_stub(struct Context*); | |
41 extern __code deleteCase2_stub(struct Context*); | |
42 extern __code deleteCase3_stub(struct Context*); | |
43 extern __code deleteCase4_stub(struct Context*); | |
44 extern __code deleteCase5_stub(struct Context*); | |
45 extern __code deleteCase6_stub(struct Context*); | |
46 extern __code createWorker_stub(struct Context*); | |
47 extern __code taskManager_stub(struct Context*); | |
90 | 48 extern __code createData1_stub(struct Context*); |
49 extern __code createData2_stub(struct Context*); | |
50 extern __code createTask1_stub(struct Context*); | |
51 extern __code createTask2_stub(struct Context*); | |
52 extern __code putQueue1_stub(struct Context*); | |
53 extern __code putQueue2_stub(struct Context*); | |
54 extern __code putQueue3_stub(struct Context*); | |
55 extern __code putQueue4_stub(struct Context*); | |
91 | 56 extern __code getQueue_stub(struct Context*); |
92 | 57 extern __code twice_stub(struct Context*); |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
58 extern __code start_time_stub(struct Context*); |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
59 extern __code end_time_stub(struct Context*); |
86 | 60 extern __code exit_code(struct Context*); |
61 | |
62 __code initContext(struct Context* context) { | |
63 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; | |
64 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); | |
65 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); | |
66 context->heapStart = malloc(context->heapLimit); | |
67 | |
68 context->codeNum = Exit; | |
69 | |
70 context->code[Code1] = code1_stub; | |
92 | 71 context->code[Code2] = code2_stub; |
86 | 72 /* context->code[Code3] = code3_stub; */ |
73 /* context->code[Code4] = code4; */ | |
74 /* context->code[Code5] = code5; */ | |
75 /* context->code[Find] = find; */ | |
76 /* context->code[Not_find] = not_find; */ | |
77 /* context->code[Code6] = code6; */ | |
90 | 78 context->code[PutTree] = put_stub; |
86 | 79 context->code[Replace] = replaceNode_stub; |
80 context->code[Insert] = insertNode_stub; | |
81 context->code[RotateL] = rotateLeft_stub; | |
82 context->code[RotateR] = rotateRight_stub; | |
83 context->code[InsertCase1] = insert1_stub; | |
84 context->code[InsertCase2] = insert2_stub; | |
85 context->code[InsertCase3] = insert3_stub; | |
86 context->code[InsertCase4] = insert4_stub; | |
87 context->code[InsertCase4_1] = insert4_1_stub; | |
88 context->code[InsertCase4_2] = insert4_2_stub; | |
89 context->code[InsertCase5] = insert5_stub; | |
90 context->code[StackClear] = stackClear_stub; | |
92 | 91 context->code[Get] = get_stub; |
92 context->code[Search] = search_stub; | |
86 | 93 /* context->code[Delete] = delete_stub; */ |
94 /* context->code[Delete1] = delete1_stub; */ | |
95 /* context->code[Delete2] = delete2_stub; */ | |
96 /* context->code[Delete3] = delete3_stub; */ | |
97 /* context->code[Replace_d1] = replaceNodeForDelete1_stub; */ | |
98 /* context->code[Replace_d2] = replaceNodeForDelete2_stub; */ | |
99 /* context->code[FindMax1] = findMax1_stub; */ | |
100 /* context->code[FindMax2] = findMax2_stub; */ | |
101 /* context->code[DeleteCase1] = deleteCase1_stub; */ | |
102 /* context->code[DeleteCase2] = deleteCase2_stub; */ | |
103 /* context->code[DeleteCase3] = deleteCase3_stub; */ | |
104 /* context->code[DeleteCase4] = deleteCase4_stub; */ | |
105 /* context->code[DeleteCase5] = deleteCase5_stub; */ | |
106 /* context->code[DeleteCase6] = deleteCase6_stub; */ | |
107 context->code[CreateWorker] = createWorker_stub; | |
108 context->code[TaskManager] = taskManager_stub; | |
90 | 109 context->code[CreateData1] = createData1_stub; |
110 context->code[CreateData2] = createData2_stub; | |
111 context->code[CreateTask1] = createTask1_stub; | |
112 context->code[CreateTask2] = createTask2_stub; | |
113 context->code[PutQueue1] = putQueue1_stub; | |
114 context->code[PutQueue2] = putQueue2_stub; | |
115 context->code[PutQueue3] = putQueue3_stub; | |
116 context->code[PutQueue4] = putQueue4_stub; | |
91 | 117 context->code[GetQueue] = getQueue_stub; |
92 | 118 context->code[Twice] = twice_stub; |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
119 context->code[StartTime] = start_time_stub; |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
120 context->code[EndTime] = end_time_stub; |
86 | 121 context->code[Exit] = exit_code; |
122 | |
123 context->heap = context->heapStart; | |
124 | |
125 context->data[Worker] = context->heap; | |
126 context->heap += sizeof(struct Worker); | |
127 | |
128 context->data[Allocate] = context->heap; | |
129 context->heap += sizeof(struct Allocate); | |
130 | |
131 context->data[Tree] = context->heap; | |
132 context->heap += sizeof(struct Tree); | |
133 | |
91 | 134 context->data[Traverse] = context->heap; |
135 context->heap += sizeof(struct Traverse); | |
136 | |
86 | 137 context->data[Node] = context->heap; |
138 context->heap += sizeof(struct Node); | |
139 | |
140 context->data[LoopCounter] = context->heap; | |
141 context->heap += sizeof(struct LoopCounter); | |
142 | |
90 | 143 context->data[Element] = context->heap; |
144 context->heap += sizeof(struct Element); | |
87 | 145 |
95
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
146 context->data[Time] = context->heap; |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
147 context->heap += sizeof(struct Time); |
3e28ee215c0e
modify twice, use OSAtomiceCompareAndSwap
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
92
diff
changeset
|
148 |
87 | 149 context->data[ActiveQueue] = context->heap; |
150 context->heap += sizeof(struct Queue); | |
151 | |
152 context->dataNum = ActiveQueue; | |
86 | 153 |
87 | 154 struct Worker* worker = &context->data[Worker]->worker; |
155 worker->num = 0; | |
156 worker->contexts = 0; | |
157 | |
90 | 158 struct Allocate* allocate = &context->data[Allocate]->allocate; |
87 | 159 allocate->size = 0; |
160 | |
86 | 161 struct Tree* tree = &context->data[Tree]->tree; |
162 tree->root = 0; | |
87 | 163 |
164 struct Node* node = &context->data[Node]->node; | |
165 node->key = 0; | |
166 node->value = 0; | |
167 node->left = 0; | |
168 node->right = 0; | |
86 | 169 |
170 struct LoopCounter* counter = &context->data[LoopCounter]->loopCounter; | |
171 counter->i = 0; | |
87 | 172 |
90 | 173 struct Element* element = &context->data[Element]->element; |
174 element->task = 0; | |
175 element->next = 0; | |
176 | |
177 struct Queue* activeQueue = &context->data[ActiveQueue]->queue; | |
178 activeQueue->first = 0; | |
179 activeQueue->last = 0; | |
180 activeQueue->count = 0; | |
86 | 181 |
182 context->node_stack = stack_init(sizeof(struct Node*), 100); | |
183 context->code_stack = stack_init(sizeof(enum Code), 100); | |
184 } |