diff src/parallel_execution/context.h @ 133:568730b1239e

call stack interface in rb_tree
author mir3636
date Mon, 07 Nov 2016 21:12:19 +0900
parents 7c309e1aea73
children 2eccf4564efe
line wrap: on
line diff
--- a/src/parallel_execution/context.h	Thu Oct 27 18:54:11 2016 +0900
+++ b/src/parallel_execution/context.h	Mon Nov 07 21:12:19 2016 +0900
@@ -10,21 +10,29 @@
 #define NEW(type) (type*)(calloc(1, sizeof(type)))
 #define NEWN(n, type) (type*)(calloc(n, sizeof(type)))
 
-#define ALLOC_DATA(context, dseg) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; })
+#define ALLOC_DATA(context, dseg) ({\
+    struct Meta* meta = (struct Meta*)context->heap;\
+    meta->type = dseg;\
+    context->heap += sizeof(struct Meta);\
+    context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; })
 
-#define ALLOC_DATA_TYPE(context, dseg, type) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct type); (struct type *)context->data[dseg]; })
+#define ALLOC_DATA_TYPE(context, dseg, t) ({\
+    struct Meta* meta = (struct Meta*)context->heap;\
+    meta->type = t;\
+    context->heap += sizeof(struct Meta);\
+    context->data[dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)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; })
+    struct Meta* meta = (struct Meta*)context->heap;\
+    context->heap += sizeof(struct Meta);\
+    union Data* data = context->heap; \
+    context->heap += sizeof(struct t); \
+    meta->type = t; \
+    data; })
 
-#define GET_DATA(spesificData) ({ \
-  union Data dummy; \
-  void* ptr = (void *)spesificData; \
-  ptr -= (void *)(&dummy.element) - (void *)(&dummy); \
-  (union Data*)ptr; })
+#define GET_TYPE(dseg) ({ \
+    struct Meta* meta = (struct Meta*)(((void*)dseg) - sizeof(struct Meta));\
+    meta->type; })
 
 enum Code {
     Code1,
@@ -141,7 +149,9 @@
 };
 
 union Data {
-    enum DataType type;
+    struct Meta {
+        enum DataType type;
+    } meta;
     struct Time {
         enum Code next;
         double time;
@@ -180,9 +190,13 @@
     struct Stack {
         union Data* stack;
         union Data* data;
+        union Data* data1;
         enum Code push;
         enum Code pop;
+        enum Code pop2;
         enum Code isEmpty;
+        enum Code whenEmpty;
+        enum Code get2;
         enum Code next;
     } stack;
     // Stack implementations