# HG changeset patch # User Tatsuki IHA # Date 1512977215 -32400 # Node ID 95f58f2b2c0eb239c0d2fe99cd1aa0f9d1b9d023 # Parent dcc42f3e7e97579b1573386da138a6d796119ff2 Add TaskIterator diff -r dcc42f3e7e97 -r 95f58f2b2c0e src/parallel_execution/TaskIterator.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/TaskIterator.cbc Mon Dec 11 16:26:55 2017 +0900 @@ -0,0 +1,28 @@ +#include "../context.h" +#include + +createTaskIterator(struct Context, struct List list) { + struct Iterator* iterator = new Iterator(); + struct TaskIterator* taskIterator = new TaskIterator(); + iterator->itearot = (union Data*)taskIterator; + iterator->exec = C_execTaskIterator; + iterator->barrier = C_barrierTaskIterator; + taskIterator->taskList = list; +} + +__code execTaskIterator(struct taskIterator* iterator, struct TaskManager* taskManager, struct Context* task, __code next(...)) { + if (iterator->list->next == null) { + goto next(...); + } + iterator->list = list->next; + struct Context* task = (struct Context*)iterator->list->data; + struct TaskManager taskManager = task->taskManager; + taskManager->spawn(task, C_execTaskIterator); +} + +__code barrierTaskIterator(struct MultiDimIterator* iterator, struct Context* task, __code next(...), __code whenWait(...)) { + if (__sync_fetch_and_sub(&iterator->count, 1) == 1) { + goto next(...); + } + goto whenWait(...); +}