Mercurial > hg > GearsTemplate
view src/parallel_execution/examples/Add.cbc @ 347:9578c38c10d1
Fix
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 30 May 2017 18:21:19 +0900 |
parents | 9f8a87389b68 |
children | 01e0fa598ce3 |
line wrap: on
line source
#include "../../context.h" CodeGear* createAddCodeGear(struct Context* context) { struct CodeGear* codeGear = new CodeGear(); struct context* addContext = NEW(struct Context); codeGear->codeGear = (union Data*)addContext; initContext(addContext); codeGear->code = C_add; codeGear->setInfo = C_setAddCodeGearInfo; return codeGear; } __code setAddCodeGearInfo(struct Context* codeGear, union Data** dataGears, __code next(...)) { codeGear->next = C_add; codeGear->idgCount = 2; codeGear->idg = codeGear->datanum; codeGear->data[codeGear->idg] = dataGears[0]; codeGear->data[codeGear->idg+1] = dataGears[1]; codeGear->maxIdg = codeGear->idg + 2; codeGear->odg = codeGear->maxIdg; codeGear->data[codeGear->odg] = dataGears[2]; task->maxOdg = task->odg + 1; goto meta(context, C_setWaitTask) } __code setAddCodeGearInfo_stub(struct Context* context) { Context* codeGear = (Context *)GearIpl(context, CodeGear, codeGear); Data* dataGears = Gearef(context, CodeGear)->dataGears; enum Code next = Gearef(context, CodeGear)->next; goto setAddCodeGearInfo(context, codeGear, dataGears, next); } __code setWaitTask(struct Context* codeGear, struct Queue* Queue, struct LoopCounter* loopCounter, union Data** dataGears, __code next(...)) { if(loopCounter->i < codeGear->idgCount) { queue->queue = (Data *)GET_WAIT_LIST(data); queue->data = codeGears[loopCoutner->i]; queue->next = C_setWaitTask; loopCounter->i++; goto meta(context, queue->queue->Queue.put); } taskManager->context = codeGear; taskManager->next = next; goto meta(context, taskManager->spawn); } __code setWaitTask_stub(struct Context* context) { Context* codeGear = GearImpl(context, CodeGear, codeGear) goto setWaitTask(context, codeGear, Gearef(context, Queue), Gearef(codeGear, LoopCounter), Gearef(context, CodeGear)->dataGears, Gearef(context, CodeGear)->next); } __code add(struct Integer* input1, struct Integer* input2, __code next(union Integer* output, ...)) { output->value = input1->value + input2->value; printf("%d + %d = %d\n", input1->value, input2->value, output->value); goto next(output, ...) }