diff src/parallel_execution/context.h @ 132:7c309e1aea73

Code Gears stack api
author one
date Thu, 27 Oct 2016 18:54:11 +0900
parents a4507906938c
children 568730b1239e
line wrap: on
line diff
--- a/src/parallel_execution/context.h	Tue Oct 25 00:49:28 2016 +0900
+++ b/src/parallel_execution/context.h	Thu Oct 27 18:54:11 2016 +0900
@@ -1,9 +1,10 @@
 /* Context definition for llrb example */
+#ifndef CONTEXT_H
+#define CONTEXT_H
 #include <pthread.h>
 #ifdef USE_CUDA
 #include <cuda.h>
 #endif
-#include "stack.h"
 
 #define ALLOCATE_SIZE 20000000
 #define NEW(type) (type*)(calloc(1, sizeof(type)))
@@ -13,6 +14,18 @@
 
 #define ALLOC_DATA_TYPE(context, dseg, type) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct type); (struct type *)context->data[dseg]; })
 
+#define ALLOCATE(context, t) ({ \
+  union Data* data = context->heap; \
+  context->heap += sizeof(struct t) + ((void *)(&data->element) - (void *)data) ; \
+  data->type = t; \
+  data; })
+
+#define GET_DATA(spesificData) ({ \
+  union Data dummy; \
+  void* ptr = (void *)spesificData; \
+  ptr -= (void *)(&dummy.element) - (void *)(&dummy); \
+  (union Data*)ptr; })
+
 enum Code {
     Code1,
     Code2,
@@ -163,25 +176,25 @@
         struct QueueInterface* i;
         enum Code next;
     } queue;
+    // Stack Interface
     struct Stack {
-        union StackSelf* stack;
+        union Data* stack;
         union Data* data;
         enum Code push;
         enum Code pop;
         enum Code isEmpty;
         enum Code next;
     } stack;
-    union StackSelf {
-        struct SingleLinkedStack {
-            struct Stack i;
-            struct Element* top;
-        } singleLinekedStack;
-        struct ArrayStack {
-            int size;
-            int limit;
-            struct Element* array;
-        } arrayStack;
-    };
+    // Stack implementations
+    struct SingleLinkedStack {
+        struct Element* top;
+    } singleLinekedStack;
+    struct ArrayStack {
+        int size;
+        int limit;
+        struct Element* array;
+    } arrayStack;
+    // Stack implementation end
     struct Element {
         union Data* data;
         struct Element* next;
@@ -199,7 +212,7 @@
         enum Code rotateNext;
         struct Node* current; // reading node of original tree
         struct Node* newNode; // writing node of new tree
-        struct Element* nodeStack;
+        struct Stack* nodeStack;
         int result;
     } traverse;
     struct Node {
@@ -226,4 +239,4 @@
     struct Queue waitMeTasks;
     struct Queue waitI;
 };
-
+#endif