comparison 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
comparison
equal deleted inserted replaced
132:7c309e1aea73 133:568730b1239e
8 8
9 #define ALLOCATE_SIZE 20000000 9 #define ALLOCATE_SIZE 20000000
10 #define NEW(type) (type*)(calloc(1, sizeof(type))) 10 #define NEW(type) (type*)(calloc(1, sizeof(type)))
11 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) 11 #define NEWN(n, type) (type*)(calloc(n, sizeof(type)))
12 12
13 #define ALLOC_DATA(context, dseg) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; }) 13 #define ALLOC_DATA(context, dseg) ({\
14 14 struct Meta* meta = (struct Meta*)context->heap;\
15 #define ALLOC_DATA_TYPE(context, dseg, type) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct type); (struct type *)context->data[dseg]; }) 15 meta->type = dseg;\
16 context->heap += sizeof(struct Meta);\
17 context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; })
18
19 #define ALLOC_DATA_TYPE(context, dseg, t) ({\
20 struct Meta* meta = (struct Meta*)context->heap;\
21 meta->type = t;\
22 context->heap += sizeof(struct Meta);\
23 context->data[dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[dseg]; })
16 24
17 #define ALLOCATE(context, t) ({ \ 25 #define ALLOCATE(context, t) ({ \
18 union Data* data = context->heap; \ 26 struct Meta* meta = (struct Meta*)context->heap;\
19 context->heap += sizeof(struct t) + ((void *)(&data->element) - (void *)data) ; \ 27 context->heap += sizeof(struct Meta);\
20 data->type = t; \ 28 union Data* data = context->heap; \
21 data; }) 29 context->heap += sizeof(struct t); \
22 30 meta->type = t; \
23 #define GET_DATA(spesificData) ({ \ 31 data; })
24 union Data dummy; \ 32
25 void* ptr = (void *)spesificData; \ 33 #define GET_TYPE(dseg) ({ \
26 ptr -= (void *)(&dummy.element) - (void *)(&dummy); \ 34 struct Meta* meta = (struct Meta*)(((void*)dseg) - sizeof(struct Meta));\
27 (union Data*)ptr; }) 35 meta->type; })
28 36
29 enum Code { 37 enum Code {
30 Code1, 38 Code1,
31 Code2, 39 Code2,
32 Code3, 40 Code3,
139 enum Code pop; 147 enum Code pop;
140 enum Code isEmpty; 148 enum Code isEmpty;
141 }; 149 };
142 150
143 union Data { 151 union Data {
144 enum DataType type; 152 struct Meta {
153 enum DataType type;
154 } meta;
145 struct Time { 155 struct Time {
146 enum Code next; 156 enum Code next;
147 double time; 157 double time;
148 } time; 158 } time;
149 struct LoopCounter { 159 struct LoopCounter {
178 } queue; 188 } queue;
179 // Stack Interface 189 // Stack Interface
180 struct Stack { 190 struct Stack {
181 union Data* stack; 191 union Data* stack;
182 union Data* data; 192 union Data* data;
193 union Data* data1;
183 enum Code push; 194 enum Code push;
184 enum Code pop; 195 enum Code pop;
196 enum Code pop2;
185 enum Code isEmpty; 197 enum Code isEmpty;
198 enum Code whenEmpty;
199 enum Code get2;
186 enum Code next; 200 enum Code next;
187 } stack; 201 } stack;
188 // Stack implementations 202 // Stack implementations
189 struct SingleLinkedStack { 203 struct SingleLinkedStack {
190 struct Element* top; 204 struct Element* top;