changeset 145:cc071cf1ba85

add stack clear interface
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 10 Nov 2016 07:51:15 +0900
parents d529c024e5a5
children 423141c31664
files src/parallel_execution/context.c src/parallel_execution/context.h src/parallel_execution/rb_tree.c src/parallel_execution/stack.c src/parallel_execution/stack.h
diffstat 5 files changed, 21 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/context.c	Thu Nov 10 07:33:10 2016 +0900
+++ b/src/parallel_execution/context.c	Thu Nov 10 07:51:15 2016 +0900
@@ -59,8 +59,6 @@
 extern __code putQueue3_stub(struct Context*);
 extern __code putQueue4_stub(struct Context*);
 extern __code getQueue_stub(struct Context*);
-extern __code pushSingleLinkedStack_stub(struct Context*);
-extern __code popSingleLinkedStack_stub(struct Context*);
 extern __code spawnTask_stub(struct Context*);
 extern __code twice_stub(struct Context*);
 extern __code start_time_stub(struct Context*);
@@ -96,6 +94,7 @@
     context->code[C_get]           = get_stub;
     context->code[C_search]        = search_stub;
 
+    context->code[C_clearSingleLinkedStack] = clearSingleLinkedStack_stub;
     context->code[C_pushSingleLinkedStack] = pushSingleLinkedStack_stub;
     context->code[C_popSingleLinkedStack] = popSingleLinkedStack_stub;
     context->code[C_pop2SingleLinkedStack] = pop2SingleLinkedStack_stub;
--- a/src/parallel_execution/context.h	Thu Nov 10 07:33:10 2016 +0900
+++ b/src/parallel_execution/context.h	Thu Nov 10 07:51:15 2016 +0900
@@ -90,6 +90,7 @@
     PutQueue3,
     PutQueue4,
     GetQueue,
+    C_clearSingleLinkedStack,
     C_pushSingleLinkedStack,
     C_popSingleLinkedStack,
     C_pop2SingleLinkedStack,
@@ -181,11 +182,13 @@
         union Data* stack;
         union Data* data;
         union Data* data1;
+        enum Code whenEmpty;
+
+        enum Code clear;
         enum Code push;
         enum Code pop;
         enum Code pop2;
         enum Code isEmpty;
-        enum Code whenEmpty;
         enum Code get;
         enum Code get2;
         enum Code next;
--- a/src/parallel_execution/rb_tree.c	Thu Nov 10 07:33:10 2016 +0900
+++ b/src/parallel_execution/rb_tree.c	Thu Nov 10 07:51:15 2016 +0900
@@ -304,16 +304,15 @@
                      parent);
 }
 
-__code stackClear(struct Context* context, struct Traverse* traverse) {
+__code stackClear(struct Context* context, struct Traverse* traverse,struct Stack *nodeStack) {
     traverse->current = 0;
-    struct SingleLinkedStack* nodeStack = (struct SingleLinkedStack*)traverse->nodeStack->stack;
-    nodeStack->top = NULL;
-
-    goto meta(context, context->next);
+    nodeStack->stack = (union Data*)traverse->nodeStack;
+    nodeStack->next = context->next;
+    goto meta(context, traverse->nodeStack->clear);
 }
 
 __code stackClear_stub(struct Context* context) {
-    goto stackClear(context, &context->data[Traverse]->traverse);
+    goto stackClear(context, &context->data[Traverse]->traverse,&context->data[Stack]->stack);
 }
     
 
--- a/src/parallel_execution/stack.c	Thu Nov 10 07:33:10 2016 +0900
+++ b/src/parallel_execution/stack.c	Thu Nov 10 07:51:15 2016 +0900
@@ -14,6 +14,7 @@
     stack->get  = C_getSingleLinkedStack;
     stack->get2  = C_get2SingleLinkedStack;
     stack->isEmpty = C_isEmptySingleLinkedStack;
+    stack->clear = C_clearSingleLinkedStack;
     return (union Data*)(stack);
 }
 
@@ -32,6 +33,15 @@
     printf("\n");
 }
 
+__code clearSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack,enum Code next) {
+    stack->top = NULL;
+    goto meta(context, next);
+}
+
+__code clearSingleLinkedStack_stub(struct Context* context) {
+    goto clearSingleLinkedStack(context, (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack, context->data[Stack]->stack.next);
+}
+
 __code pushSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, struct Element* element, union Data* data, enum Code next) {
     element->next = stack->top;
     element->data = data;
--- a/src/parallel_execution/stack.h	Thu Nov 10 07:33:10 2016 +0900
+++ b/src/parallel_execution/stack.h	Thu Nov 10 07:51:15 2016 +0900
@@ -6,3 +6,4 @@
 extern __code getSingleLinkedStack_stub(struct Context* context) ;
 extern __code get2SingleLinkedStack_stub(struct Context* context) ;
 extern __code isEmptySingleLinkedStack_stub(struct Context* context) ;
+extern __code clearSingleLinkedStack_stub(struct Context* context) ;