Mercurial > hg > GearsTemplate
changeset 399:394e38952c80
Add dummy data to SingleLinkedQueue
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 29 Aug 2017 04:28:13 +0900 |
parents | fc4fcd441700 |
children | 2d375c583064 |
files | src/parallel_execution/SingleLinkedQueue.cbc src/parallel_execution/TaskManagerImpl.cbc src/parallel_execution/generate_stub.pl src/parallel_execution/test/queue_test.cbc |
diffstat | 4 files changed, 29 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/SingleLinkedQueue.cbc Tue Aug 29 01:01:44 2017 +0900 +++ b/src/parallel_execution/SingleLinkedQueue.cbc Tue Aug 29 04:28:13 2017 +0900 @@ -5,8 +5,8 @@ struct Queue* queue = new Queue(); struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue(); queue->queue = (union Data*)singleLinkedQueue; - singleLinkedQueue->top = NULL; - singleLinkedQueue->last = NULL; + singleLinkedQueue->top = new Element(); + singleLinkedQueue->last = singleLinkedQueue->top; queue->take = C_takeSingleLinkedQueue; queue->put = C_putSingleLinkedQueue; queue->isEmpty = C_isEmptySingleLinkedQueue; @@ -36,33 +36,29 @@ __code putSingleLinkedQueue(struct SingleLinkedQueue* queue, union Data* data, __code next(...)) { Element* element = new Element(); + element->data = data; element->next = NULL; - element->data = data; - if (queue->last) { - Element* last = queue->last; - last->next = element; - queue->last = element; - } else { - queue->top = element; - queue->last = element; - } + queue->last->next = element; + queue->last = element; goto next(...); } __code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(union Data* data, ...)) { - if (queue->top) { - data = queue->top->data; - queue->top = queue->top->next; + struct Element* top = queue->top; + struct Element* nextElement = top->next; + if (queue->top == queue->last) { + data = NULL; } else { - data = NULL; + queue->top = nextElement; + data = nextElement->data; } goto next(data, ...); } __code isEmptySingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...), __code whenEmpty(...)) { - if (queue->top) + if (queue->top == queue->last) + goto whenEmpty(...); + else goto next(...); - else - goto whenEmpty(...); }
--- a/src/parallel_execution/TaskManagerImpl.cbc Tue Aug 29 01:01:44 2017 +0900 +++ b/src/parallel_execution/TaskManagerImpl.cbc Tue Aug 29 04:28:13 2017 +0900 @@ -59,6 +59,14 @@ goto meta(context, tasks->isEmpty); } +__code spawnTasksTaskManagerImpl_stub(struct Context* context) { + TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); + Queue* tasks = Gearef(context, TaskManager)->tasks; + enum Code next1 = Gearef(context, TaskManager)->next1; + Queue* queue = Gearef(context, Queue); + goto spawnTasksTaskManagerImpl(context, taskManager, tasks, next1, queue); +} + __code spawnTasksTaskManagerImpl1(struct TaskManagerImpl* taskManager, struct Queue* tasks, __code next1(...), struct Queue* queue) { queue->queue = (union Data*)tasks; queue->next = C_spawnTasksTaskManagerImpl2;
--- a/src/parallel_execution/generate_stub.pl Tue Aug 29 01:01:44 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Tue Aug 29 04:28:13 2017 +0900 @@ -448,14 +448,10 @@ ${prev}element = &ALLOCATE(context, Element)->Element; ${prev}element->next = NULL; ${prev}element->data = (union Data*)task; -${prev}if (queue->last) { -${prev} Element* last = queue->last; -${prev} last->next = element; -${prev} queue->last = element; -${prev}} else { -${prev} queue->top = element; -${prev} queue->last = element; -${prev}} +${prev}element->data = data; +${prev}element->next = NULL; +${prev}queue->last->next = element; +${prev}queue->last = element; EOFEOF print $fd $putTask; next;
--- a/src/parallel_execution/test/queue_test.cbc Tue Aug 29 01:01:44 2017 +0900 +++ b/src/parallel_execution/test/queue_test.cbc Tue Aug 29 04:28:13 2017 +0900 @@ -16,7 +16,7 @@ __code queueTest2_stub(struct Context* context) { SingleLinkedQueue* singleLinkedQueue = (SingleLinkedQueue*)GearImpl(context, Queue, queue); - assert(singleLinkedQueue->top->data->Node.color == Red); + assert(singleLinkedQueue->top->next->data->Node.color == Red); assert(singleLinkedQueue->last->data->Node.color == Red); Queue* queue = Gearef(context, Queue); goto queueTest2(context, queue); @@ -28,7 +28,7 @@ __code queueTest3_stub(struct Context* context) { SingleLinkedQueue* singleLinkedQueue = (SingleLinkedQueue*)GearImpl(context, Queue, queue); - assert(singleLinkedQueue->top->data->Node.color == Red); + assert(singleLinkedQueue->top->next->data->Node.color == Red); assert(singleLinkedQueue->last->data->Node.color == Black); Queue* queue = Gearef(context, Queue); goto queueTest3(context, queue); @@ -36,7 +36,7 @@ __code assert3(struct Queue* queue) { SingleLinkedQueue* singleLinkedQueue = &queue->queue->Queue.queue->SingleLinkedQueue; - assert(singleLinkedQueue->top->data->Node.color == Black); + assert(singleLinkedQueue->top->next->data->Node.color == Black); assert(singleLinkedQueue->last->data->Node.color == Black); goto exit_code(context); }