Mercurial > hg > Gears > GearsAgda
view src/parallel_execution/OneDimIterator.cbc @ 374:fb50cf8aa615
Add Iterator Interface
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Jul 2017 15:14:08 +0900 |
parents | |
children | ad44fdb11433 |
line wrap: on
line source
#include "../context.h" #include <stdio.h> Iterator createOneDimIterator(struct Context* context, int x) { struct Iterator* iterator = new Iterator(); struct OneDimIterator* oneDimIterator = new OneDimIterator(); iterator->iterator = (union Data*)oneDimIterator; iterator->exec = C_execOneDimIterator; iterator->barrier = C_barrierOneDimItearator; oneDimIterator->x = x; oneDimIterator->count = x; iterator->loopCounter = new LoopCounter(); iterator->loopCounter->i = 0; oneDimIterator->exec = C_execOneDimIterator; } __code execOneDimIterator(struct OneDimIterator* oneDimIterator, struct TaskManager* taskManager, struct context* task, __code next(...)) { if (oneDimIterator->loopCounter->i == oneDimIterator->x) { oneDimIterator->loopCounter->i = 0; goto next(...); } struct context* iterate_task = NEW(struct Context); *iterate_task = *task; task->iterate = 1; oneDimIterator->loopCounter->i++; taskManager->taskManager = (union Data*)task->taskManager; taskManager->task = iterate_task; taskManager->next = C_execOneDimIterator; goto meta(context, C_execOneDimIterator); } __code barrierOneDimIterator(struct OneDimIterator* oneDimIterator, struct context* task, __code next(...), __code whenWait(...)) { if (__sync_fetch_and_sub(&oneDimIterator->count, 1) == 1) { goto next(...); } goto whenWait(...); }