Mercurial > hg > GearsTemplate
diff src/parallel_execution/examples/boundedBuffer/BoundedBuffer.cbc @ 494:d8b2036c6942
BoundedBuffer implments Buffer interface
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 31 Dec 2017 02:40:08 +0900 |
parents | 82f0c49750f1 |
children | 2e7ea81e5943 |
line wrap: on
line diff
--- a/src/parallel_execution/examples/boundedBuffer/BoundedBuffer.cbc Sun Dec 31 01:36:18 2017 +0900 +++ b/src/parallel_execution/examples/boundedBuffer/BoundedBuffer.cbc Sun Dec 31 02:40:08 2017 +0900 @@ -1,9 +1,9 @@ #include "../../../context.h" -#interface "Queue.h" +#interface "Buffer.h" #interface "Semaphore.h" -Queue* createBoundedBuffer(struct Context* context, int size) { - struct Queue* queue = new Queue(); +Buffer* createBoundedBuffer(struct Context* context, int size) { + struct Buffer* buffer = new Buffer(); struct BoundedBuffer* boundedBuffer = new BoundedBuffer(); boundedBuffer->top = new Element(); boundedBuffer->top->next = NULL; @@ -11,66 +11,65 @@ boundedBuffer->fullCount = createSemaphoreImpl(context, 0); boundedBuffer->emptyCount = createSemaphoreImpl(context, size); boundedBuffer->lock = createSemaphoreImpl(context, 1); // binary semaphore - queue->queue = (union Data*)boundedBuffer; - queue->take = C_takeBoundedBuffer; - queue->put = C_putBoundedBuffer; - // queue->isEmpty = C_isEmptyBoundedBuffer; - // queue->clear = C_clearBoundedBuffer; - return queue; + buffer->buffer = (union Data*)boundedBuffer; + buffer->take = C_takeBoundedBuffer; + buffer->put = C_putBoundedBuffer; + return buffer; } -__code putBoundedBuffer(struct BoundedBuffer* queue, union Data* data, __code next(...)) { - struct Semaphore* sem = queue->emptyCount; +__code putBoundedBuffer(struct BoundedBuffer* buffer, union Data* data, __code next(...)) { + struct Semaphore* sem = buffer->emptyCount; goto sem->p(putBoundedBuffer1); } -__code putBoundedBuffer1(struct BoundedBuffer* queue, union Data* data, __code next(...)) { - struct Semaphore* sem = queue->lock; +__code putBoundedBuffer1(struct BoundedBuffer* buffer, union Data* data, __code next(...)) { + struct Semaphore* sem = buffer->lock; goto sem->p(putBoundedBuffer2); } -__code putBoundedBuffer2(struct BoundedBuffer* queue, union Data* data, __code next(...)) { +__code putBoundedBuffer2(struct BoundedBuffer* buffer, union Data* data, __code next(...)) { struct Element* element = new Element(); element->data = data; element->next = NULL; - struct Element* last = queue->last; + struct Element* last = buffer->last; last->next = element; - struct Semaphore* sem = queue->lock; + printf("put\n"); + struct Semaphore* sem = buffer->lock; goto sem->v(putBoundedBuffer3); } -__code putBoundedBuffer3(struct BoundedBuffer* queue, union Data* data, __code next(...)) { - struct Semaphore* sem = queue->fullCount; +__code putBoundedBuffer3(struct BoundedBuffer* buffer, union Data* data, __code next(...)) { + struct Semaphore* sem = buffer->fullCount; goto sem->v(putBoundedBuffer4); } -__code putBoundedBuffer4(struct BoundedBuffer* queue, union Data* data, __code next(...)) { - goto next(data, ...); +__code putBoundedBuffer4(struct BoundedBuffer* buffer, union Data* data, __code next(...)) { + goto next(...); } -__code takeBoundedBuffer(struct BoundedBuffer* queue, __code next(union Data* data, ...)) { - struct Semaphore* sem = queue->fullCount; +__code takeBoundedBuffer(struct BoundedBuffer* buffer, __code next(union Data* data, ...)) { + struct Semaphore* sem = buffer->fullCount; goto sem->p(takeBoundedBuffer1); } -__code takeBoundedBuffer1(struct BoundedBuffer* queue, __code next(union Data* data, ...)) { - struct Semaphore* sem = queue->lock; +__code takeBoundedBuffer1(struct BoundedBuffer* buffer, __code next(union Data* data, ...)) { + struct Semaphore* sem = buffer->lock; goto sem->p(takeBoundedBuffer2); } -__code takeBoundedBuffer2(struct BoundedBuffer* queue, __code next(union Data* data, ...)) { - struct Element* top = queue->top; +__code takeBoundedBuffer2(struct BoundedBuffer* buffer, __code next(union Data* data, ...)) { + struct Element* top = buffer->top; struct Element* nextElement = top->next; data = nextElement->data; - queue->top = nextElement; - struct Semaphore* sem = queue->lock; + buffer->top = nextElement; + struct Semaphore* sem = buffer->lock; goto sem->v(takeBoundedBuffer3); } -__code takeBoundedBuffer3(struct BoundedBuffer* queue, __code next(union Data* data, ...)) { - struct Semaphore* sem = queue->emptyCount; +__code takeBoundedBuffer3(struct BoundedBuffer* buffer, __code next(union Data* data, ...)) { + struct Semaphore* sem = buffer->emptyCount; goto sem->v(takeBoundedBuffer4); } -__code takeBoundedBuffer4(struct BoundedBuffer* queue, __code next(union Data* data, ...)) { +__code takeBoundedBuffer4(struct BoundedBuffer* buffer, __code next(union Data* data, ...)) { goto next(data, ...); }