Mercurial > hg > Members > innparusu > Gears
diff 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 |
line wrap: on
line diff
--- a/src/parallel_execution/main.c Tue Jan 26 06:47:35 2016 +0900 +++ b/src/parallel_execution/main.c Tue Jan 26 07:46:26 2016 +0900 @@ -26,9 +26,10 @@ } __code code1(struct Context* context) { - print_queue(context->activeQueue->first); - puts(""); - print_tree(context->tree->root); + puts("queue"); + print_queue(context->data[ActiveQueue]->queue.first); + puts("tree"); + print_tree(context->data[Tree]->tree.root); goto meta(context, Exit); } @@ -166,12 +167,38 @@ goto putQueue4(context, &context->data[ActiveQueue]->queue, &context->data[context->dataNum]->element); } +__code getQueue(struct Context* context, struct Queue* queue) { + if (queue->count == 0) + return; + + struct Element* first = queue->first; + if (__sync_bool_compare_and_swap(&queue->first, first, first->next)) { + queue->count--; + + context->next = GetQueue; + stack_push(context->code_stack, &context->next); + + context->next = first->task->code; + stack_push(context->code_stack, &context->next); + + goto meta(context, Search); + } else { + goto meta(context, GetQueue); + } +} + +__code getQueue_stub(struct Context* context) { + goto getQueue(context, &context->data[ActiveQueue]->queue); +} + __code createWorker(struct Context* context, struct LoopCounter* loopCounter, struct Worker* worker) { int i = loopCounter->i; if (i < worker->num) { struct Context* worker_context = &worker->contexts[i]; - worker_context->next = Code1; + worker_context->next = GetQueue; + worker_context->data[Tree] = context->data[Tree]; + worker_context->data[ActiveQueue] = context->data[ActiveQueue]; pthread_create(&worker_context->thread, NULL, (void*)&start_code, worker_context); loopCounter->i++;