Mercurial > hg > GearsTemplate
changeset 287:6b099d73949c
Add queueCount sem to SynchronizedQueue
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 06 Feb 2017 00:59:39 +0900 |
parents | fd470e090403 |
children | f1b0cc555b6e |
files | src/parallel_execution/SynchronizedQueue.cbc src/parallel_execution/context.h src/parallel_execution/main.cbc |
diffstat | 3 files changed, 20 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/SynchronizedQueue.cbc Sun Feb 05 22:15:27 2017 +0900 +++ b/src/parallel_execution/SynchronizedQueue.cbc Mon Feb 06 00:59:39 2017 +0900 @@ -7,6 +7,7 @@ struct SynchronizedQueue* synchronizedQueue = new SynchronizedQueue(); synchronizedQueue->top = NULL; synchronizedQueue->last = NULL; + synchronizedQueue ->queueCount = createSemaphoreImpl(context, 0); queue->queue = (union Data*)synchronizedQueue; queue->take = C_takeSynchronizedQueue; queue->put = C_putSynchronizedQueue; @@ -42,17 +43,25 @@ goto meta(context, C_putSynchronizedQueue); } } - goto next(...); + goto meta(context, C_putSynchronizedQueue1); +} + +__code putSynchronizedQueue1(struct SynchronizedQueue* queue, union Data* data, struct Semaphore* semaphore, __code next(...)) { + semaphore->semaphore = (union Data*)queue->queueCount; + semaphore->next = next; + goto meta(context, queue->queueCount->v); } -__code takeSynchronizedQueue(struct SynchronizedQueue* queue, __code next(union Data* data, ...)) { - if (queue->top) { - struct Element* top = queue->top; - if (__sync_bool_compare_and_swap(&queue->top, top, top->next)) { - data = top->data; - } else { - goto meta(context, C_takeSynchronizedQueue); - } +__code takeSynchronizedQueue(struct SynchronizedQueue* queue, struct Semaphore* semaphore) { + semaphore->semaphore = (union Data*)queue->queueCount; + semaphore->next = C_takeSynchronizedQueue1; + goto meta(context, queue->queueCount->p); +} + +__code takeSynchronizedQueue1(struct SynchronizedQueue* queue, __code next(union Data* data, ...)) { + struct Element* top = queue->top; + if (__sync_bool_compare_and_swap(&queue->top, top, top->next)) { + data = top->data; } else { goto meta(context, C_takeSynchronizedQueue); }
--- a/src/parallel_execution/context.h Sun Feb 05 22:15:27 2017 +0900 +++ b/src/parallel_execution/context.h Mon Feb 06 00:59:39 2017 +0900 @@ -179,6 +179,7 @@ struct SynchronizedQueue { struct Element* top; struct Element* last; + struct Semaphore* queueCount; } SynchronizedQueue; // Stack Interface struct Stack {
--- a/src/parallel_execution/main.cbc Sun Feb 05 22:15:27 2017 +0900 +++ b/src/parallel_execution/main.cbc Mon Feb 06 00:59:39 2017 +0900 @@ -59,7 +59,7 @@ int i = loopCounter->i; if (i < length) { - printf("%d\n", array_ptr[i]); + //printf("%d\n", array_ptr[i]); if (array_ptr[i] == (i*2)) { loopCounter->i++; goto meta(context, C_code2); @@ -185,4 +185,3 @@ goto start_code(main_context); } -