# HG changeset patch # User Tatsuki IHA # Date 1486310379 -32400 # Node ID 6b099d73949c0fdae714006bbcb6094d87cf9b56 # Parent fd470e0904037ca5cf2450aee3e7d8c277fdab15 Add queueCount sem to SynchronizedQueue diff -r fd470e090403 -r 6b099d73949c src/parallel_execution/SynchronizedQueue.cbc --- 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); } diff -r fd470e090403 -r 6b099d73949c src/parallel_execution/context.h --- 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 { diff -r fd470e090403 -r 6b099d73949c src/parallel_execution/main.cbc --- 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); } -