Mercurial > hg > Members > innparusu > Gears
comparison src/parallel_execution/main.c @ 91:1e074c3878c7
modify tree
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Jan 2016 07:46:26 +0900 |
parents | 4b5bf5b40970 |
children | 851da1107223 |
comparison
equal
deleted
inserted
replaced
90:4b5bf5b40970 | 91:1e074c3878c7 |
---|---|
24 print_tree(node->right); | 24 print_tree(node->right); |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 __code code1(struct Context* context) { | 28 __code code1(struct Context* context) { |
29 print_queue(context->activeQueue->first); | 29 puts("queue"); |
30 puts(""); | 30 print_queue(context->data[ActiveQueue]->queue.first); |
31 print_tree(context->tree->root); | 31 puts("tree"); |
32 print_tree(context->data[Tree]->tree.root); | |
32 | 33 |
33 goto meta(context, Exit); | 34 goto meta(context, Exit); |
34 } | 35 } |
35 | 36 |
36 __code code1_stub(struct Context* context) { | 37 __code code1_stub(struct Context* context) { |
164 | 165 |
165 __code putQueue4_stub(struct Context* context) { | 166 __code putQueue4_stub(struct Context* context) { |
166 goto putQueue4(context, &context->data[ActiveQueue]->queue, &context->data[context->dataNum]->element); | 167 goto putQueue4(context, &context->data[ActiveQueue]->queue, &context->data[context->dataNum]->element); |
167 } | 168 } |
168 | 169 |
170 __code getQueue(struct Context* context, struct Queue* queue) { | |
171 if (queue->count == 0) | |
172 return; | |
173 | |
174 struct Element* first = queue->first; | |
175 if (__sync_bool_compare_and_swap(&queue->first, first, first->next)) { | |
176 queue->count--; | |
177 | |
178 context->next = GetQueue; | |
179 stack_push(context->code_stack, &context->next); | |
180 | |
181 context->next = first->task->code; | |
182 stack_push(context->code_stack, &context->next); | |
183 | |
184 goto meta(context, Search); | |
185 } else { | |
186 goto meta(context, GetQueue); | |
187 } | |
188 } | |
189 | |
190 __code getQueue_stub(struct Context* context) { | |
191 goto getQueue(context, &context->data[ActiveQueue]->queue); | |
192 } | |
193 | |
169 __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { | 194 __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { |
170 int i = loopCounter->i; | 195 int i = loopCounter->i; |
171 | 196 |
172 if (i < worker->num) { | 197 if (i < worker->num) { |
173 struct Context* worker_context = &worker->contexts[i]; | 198 struct Context* worker_context = &worker->contexts[i]; |
174 worker_context->next = Code1; | 199 worker_context->next = GetQueue; |
200 worker_context->data[Tree] = context->data[Tree]; | |
201 worker_context->data[ActiveQueue] = context->data[ActiveQueue]; | |
175 pthread_create(&worker_context->thread, NULL, (void*)&start_code, worker_context); | 202 pthread_create(&worker_context->thread, NULL, (void*)&start_code, worker_context); |
176 loopCounter->i++; | 203 loopCounter->i++; |
177 | 204 |
178 goto meta(context, CreateWorker); | 205 goto meta(context, CreateWorker); |
179 } | 206 } |