Mercurial > hg > GearsTemplate
comparison src/parallel_execution/main.c @ 170:ee7134f3bef1
Fix
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Nov 2016 10:36:45 +0900 |
parents | ea7b11f3e717 |
children | 57a11c15ff4c |
comparison
equal
deleted
inserted
replaced
169:ea7b11f3e717 | 170:ee7134f3bef1 |
---|---|
111 Gearef(context, Tree)); | 111 Gearef(context, Tree)); |
112 } | 112 } |
113 | 113 |
114 __code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Queue* waitMe, struct Queue* waitI, struct Element* element) { | 114 __code createTask1(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Queue* waitMe, struct Queue* waitI, struct Element* element) { |
115 int i = loopCounter->i; | 115 int i = loopCounter->i; |
116 | |
117 waitMe->first = 0; | |
118 waitMe->last = 0; | |
119 waitMe->count = 0; | |
120 | |
121 waitI->first = 0; | |
122 waitI->last = 0; | |
123 waitI->count = 0; | |
124 | 116 |
125 task->code = Twice; | 117 task->code = Twice; |
126 task->key = i; | 118 task->key = i; |
127 task->waitMe = waitMe; | 119 task->waitMe = waitMe; |
128 task->waitI = waitI; | 120 task->waitI = waitI; |
192 // goto createTask2(context, | 184 // goto createTask2(context, |
193 // &context->data[context->dataNum]->task, | 185 // &context->data[context->dataNum]->task, |
194 // &context->data[Element]->element); | 186 // &context->data[Element]->element); |
195 //} | 187 //} |
196 | 188 |
197 __code putQueue1(struct Context* context, struct Allocate* allocate) { | |
198 allocate->size = sizeof(struct Element); | |
199 allocator(context); | |
200 | |
201 goto meta(context, PutQueue2); | |
202 } | |
203 | |
204 __code putQueue1_stub(struct Context* context) { | |
205 goto putQueue1(context, &context->data[D_Allocate]->allocate); | |
206 } | |
207 | |
208 __code putQueue2(struct Context* context, struct Element* new_element, struct Element* element, struct Queue* queue) { | |
209 new_element->data = element->data; | |
210 | |
211 if (queue->first) | |
212 goto meta(context, PutQueue3); | |
213 else | |
214 goto meta(context, PutQueue4); | |
215 } | |
216 | |
217 __code putQueue2_stub(struct Context* context) { | |
218 goto putQueue2(context, | |
219 &context->data[context->dataNum]->element, | |
220 &context->data[D_Element]->element, | |
221 &context->data[D_Queue]->Queue); | |
222 } | |
223 | |
224 __code putQueue3(struct Context* context, struct Queue* queue, struct Element* new_element) { | |
225 struct Element* last = queue->last; | |
226 | |
227 if (__sync_bool_compare_and_swap(&queue->last, last, new_element)) { | |
228 last->next = new_element; | |
229 queue->count++; | |
230 | |
231 goto meta(context, context->next); | |
232 } else { | |
233 goto meta(context, PutQueue3); | |
234 } | |
235 } | |
236 | |
237 __code putQueue3_stub(struct Context* context) { | |
238 goto putQueue3(context, &context->data[D_Queue]->Queue, &context->data[context->dataNum]->element); | |
239 } | |
240 | |
241 __code putQueue4(struct Context* context, struct Queue* queue, struct Element* new_element) { | |
242 if (__sync_bool_compare_and_swap(&queue->first, 0, new_element)) { | |
243 queue->last = new_element; | |
244 queue->count++; | |
245 | |
246 goto meta(context, context->next); | |
247 } else { | |
248 goto meta(context, PutQueue3); | |
249 } | |
250 } | |
251 | |
252 __code putQueue4_stub(struct Context* context) { | |
253 goto putQueue4(context, &context->data[D_Queue]->Queue, &context->data[context->dataNum]->element); | |
254 } | |
255 | |
256 __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { | 189 __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { |
257 int i = loopCounter->i; | 190 int i = loopCounter->i; |
258 | 191 |
259 if (i < worker->num) { | 192 if (i < worker->num) { |
260 struct Context* worker_context = &worker->contexts[i]; | 193 struct Context* worker_context = &worker->contexts[i]; |
261 worker_context->next = GetQueue; | 194 worker_context->next = C_getTask1; |
262 worker_context->data[D_Tree] = context->data[D_Tree]; | 195 worker_context->data[D_Tree] = context->data[D_Tree]; |
263 worker_context->data[D_ActiveQueue] = context->data[D_ActiveQueue]; | 196 worker_context->data[D_ActiveQueue] = context->data[D_ActiveQueue]; |
264 pthread_create(&worker_context->thread, NULL, (void*)&start_code, worker_context); | 197 pthread_create(&worker_context->thread, NULL, (void*)&start_code, worker_context); |
265 worker_context->thread_num = i; | 198 worker_context->thread_num = i; |
266 loopCounter->i++; | 199 loopCounter->i++; |