changeset 516:62a77785cb2b

Bounded Loop for boundedBuffer examples
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 04 Jan 2018 19:50:46 +0900
parents 64869af1f3ef
children d595acd16550
files src/parallel_execution/context.h src/parallel_execution/examples/boundedBuffer/consumer.cbc src/parallel_execution/examples/boundedBuffer/initBuffer.cbc src/parallel_execution/examples/boundedBuffer/main.cbc src/parallel_execution/examples/boundedBuffer/producer.cbc src/parallel_execution/generate_stub.pl
diffstat 6 files changed, 40 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/context.h	Wed Jan 03 17:34:24 2018 +0900
+++ b/src/parallel_execution/context.h	Thu Jan 04 19:50:46 2018 +0900
@@ -427,7 +427,7 @@
         struct Context* lockContext;
     } LockImpl;
     struct SpinLock {
-        Int* lock;
+        volatile Int* lock;
         struct Atomic* atomic;
         struct Context* lockContext;
     } SpinLock;
--- a/src/parallel_execution/examples/boundedBuffer/consumer.cbc	Wed Jan 03 17:34:24 2018 +0900
+++ b/src/parallel_execution/examples/boundedBuffer/consumer.cbc	Thu Jan 04 19:50:46 2018 +0900
@@ -2,17 +2,24 @@
 #include <stdio.h>
 #interface "Buffer.h"
 
-__code consumer(struct Buffer* buffer, __code next(...)) {
-    goto buffer->take(consumer1);
+__code consumer(struct Buffer* buffer, Int length, __code next(...), struct LoopCounter* loopCounter) {
+    int i = loopCounter->i;
+    if (i < length) {
+        loopCounter->i++;
+        goto buffer->take(consumer1);
+    }
+    goto next(...);
 }
 
 __code consumer_stub(struct Context* context) {
     goto consumer(context,
                   &context->data[context->idg]->Buffer,
-                  context->next);
+                  context->data[context->idg+1]->Int,
+                  context->next,
+                  Gearef(context, LoopCounter));
 }
 
-__code consumer1(struct Buffer* buffer, __code next(...), struct Node* node) {
+__code consumer1(struct Buffer* buffer, Int length, __code next(...), struct Node* node) {
     printf("getData %d\n", node->value->Int);
     goto consumer();
 }
@@ -20,6 +27,7 @@
 __code consumer1_stub(struct Context* context) {
     goto consumer1(context,
                    &context->data[context->idg]->Buffer,
+                   context->data[context->idg+1]->Int,
                    context->next,
                    &Gearef(context, Buffer)->data->Node);
 }
--- a/src/parallel_execution/examples/boundedBuffer/initBuffer.cbc	Wed Jan 03 17:34:24 2018 +0900
+++ b/src/parallel_execution/examples/boundedBuffer/initBuffer.cbc	Thu Jan 04 19:50:46 2018 +0900
@@ -1,13 +1,16 @@
 #include "../../../context.h"
 
-__code initBuffer(__code next(struct Buffer* output, ...)) {
+__code initBuffer(__code next(struct Buffer* output, Int* output1, ...)) {
     struct Buffer* output = *O_output;
-    goto next(output, ...);
+    Int* output1 = *O_output1;
+    goto next(output, output1, ...);
 }
 
 __code initBuffer_stub(struct Context* context) {
     struct Buffer** O_output = (struct Buffer**)&context->data[context->odg];
+    Int** O_output1 = (Int**)&context->data[context->odg+1];
     goto initBuffer(context,
                   context->next,
-                  O_output);
+                  O_output,
+                  O_output1);
 }
--- a/src/parallel_execution/examples/boundedBuffer/main.cbc	Wed Jan 03 17:34:24 2018 +0900
+++ b/src/parallel_execution/examples/boundedBuffer/main.cbc	Thu Jan 04 19:50:46 2018 +0900
@@ -50,11 +50,13 @@
 
 __code createTask1(struct TaskManager* taskManager) {
     struct Buffer* buffer = createBoundedBuffer(context, buffer_size);
-    par goto producer(buffer, __exit);
-    par goto producer(buffer, __exit);
-    par goto consumer(buffer, __exit);
-    par goto consumer(buffer, __exit);
-    par goto initBuffer(buffer, __exit);
+    Int* len = new Int();
+    *len = length;
+    par goto producer(buffer, len, __exit);
+    par goto producer(buffer, len, __exit);
+    par goto consumer(buffer, len, __exit);
+    par goto consumer(buffer, len, __exit);
+    par goto initBuffer(buffer, len, __exit);
     goto code2();
 }
 
--- a/src/parallel_execution/examples/boundedBuffer/producer.cbc	Wed Jan 03 17:34:24 2018 +0900
+++ b/src/parallel_execution/examples/boundedBuffer/producer.cbc	Thu Jan 04 19:50:46 2018 +0900
@@ -1,15 +1,22 @@
 #include "../../../context.h"
 #interface "Buffer.h"
 
-__code producer(struct Buffer* buffer, __code next(...)) {
-    Node* node = new Node();
-    node->value = (union Data*)new Int();
-    node->value->Int = 10;
-    goto buffer->put(node, producer);
+__code producer(struct Buffer* buffer, Int length, __code next(...), struct LoopCounter* loopCounter) {
+    int i = loopCounter->i;
+    if (i < length) {
+        Node* node = new Node();
+        node->value = (union Data*)new Int();
+        node->value->Int = i;
+        loopCounter->i++;
+        goto buffer->put(node, producer);
+    }
+    goto next(...);
 }
 
 __code producer_stub(struct Context* context) {
     goto producer(context,
                   &context->data[context->idg]->Buffer,
-                  context->next);
+                  context->data[context->idg+1]->Int,
+                  context->next,
+                  Gearef(context, LoopCounter));
 }
--- a/src/parallel_execution/generate_stub.pl	Wed Jan 03 17:34:24 2018 +0900
+++ b/src/parallel_execution/generate_stub.pl	Thu Jan 04 19:50:46 2018 +0900
@@ -188,7 +188,7 @@
                     $inputIncFlag = 0;
                     $outputCount = split(/,/,$3);
                     $outputCount--;
-                } elsif ($args =~ s/^(struct|union)?\s*(\w+)(\*)+\s(\w+)//) {
+                } elsif ($args =~ s/^(struct|union)?\s*(\w+)(\*)?+\s(\w+)//) {
                     if($inputIncFlag) {
                         $inputCount++;
                     }