Mercurial > hg > GearsTemplate
comparison src/parallel_execution/context.h @ 236:865179a0a56d
fix taskManager
author | ikkun |
---|---|
date | Mon, 23 Jan 2017 20:00:46 +0900 |
parents | 47588c28f189 |
children | 6f6cc49213c5 |
comparison
equal
deleted
inserted
replaced
235:05e61405cc88 | 236:865179a0a56d |
---|---|
12 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) | 12 #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) |
13 | 13 |
14 #define ALLOC_DATA(context, dseg) ({\ | 14 #define ALLOC_DATA(context, dseg) ({\ |
15 struct Meta* meta = (struct Meta*)context->heap;\ | 15 struct Meta* meta = (struct Meta*)context->heap;\ |
16 meta->type = D_##dseg;\ | 16 meta->type = D_##dseg;\ |
17 meta->size = 1;\ | |
17 context->heap += sizeof(struct Meta);\ | 18 context->heap += sizeof(struct Meta);\ |
18 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[D_##dseg]; }) | 19 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[D_##dseg]; }) |
19 | 20 |
20 #define ALLOC_DATA_TYPE(context, dseg, t) ({\ | 21 #define ALLOC_DATA_TYPE(context, dseg, t) ({\ |
21 struct Meta* meta = (struct Meta*)context->heap;\ | 22 struct Meta* meta = (struct Meta*)context->heap;\ |
22 meta->type = D_##t;\ | 23 meta->type = D_##t;\ |
23 context->heap += sizeof(struct Meta);\ | 24 meta->size = 1;\ |
25 context->heap += sizeof(struct Meta); \ | |
24 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[D_##dseg]; }) | 26 context->data[D_##dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[D_##dseg]; }) |
25 | 27 |
26 #define ALLOCATE(context, t) ({ \ | 28 #define ALLOCATE(context, t) ({ \ |
27 struct Meta* meta = (struct Meta*)context->heap;\ | 29 struct Meta* meta = (struct Meta*)context->heap;\ |
28 context->heap += sizeof(struct Meta);\ | 30 context->heap += sizeof(struct Meta);\ |
29 union Data* data = context->heap; \ | 31 union Data* data = context->heap; \ |
30 context->heap += sizeof(struct t); \ | 32 context->heap += sizeof(struct t); \ |
31 meta->type = D_##t; \ | 33 meta->type = D_##t; \ |
34 meta->size = 1; \ | |
32 data; }) | 35 data; }) |
33 | 36 |
34 #define ALLOC(context, t) (&ALLOCATE(context, t)->t) | 37 #define ALLOC(context, t) (&ALLOCATE(context, t)->t) |
38 | |
39 #define ALLOC_ARRY(context, dseg, size) ({\ | |
40 struct Meta* meta = (struct Meta*)context->heap;\ | |
41 context->heap += sizeof(struct Meta);\ | |
42 union Data* data = context->heap; \ | |
43 context->heap += sizeof(struct t)*size; \ | |
44 meta->type = D_##dseg; \ | |
45 meta->size = size; \ | |
46 data; }) | |
35 | 47 |
36 #define GET_TYPE(dseg) ({ \ | 48 #define GET_TYPE(dseg) ({ \ |
37 struct Meta* meta = (struct Meta*)(((void*)dseg) - sizeof(struct Meta));\ | 49 struct Meta* meta = (struct Meta*)(((void*)dseg) - sizeof(struct Meta));\ |
38 meta->type; }) | 50 meta->type; }) |
39 | 51 |
60 int codeNum; | 72 int codeNum; |
61 __code (**code) (struct Context*); | 73 __code (**code) (struct Context*); |
62 void* heapStart; | 74 void* heapStart; |
63 void* heap; | 75 void* heap; |
64 long heapLimit; | 76 long heapLimit; |
65 int thread_num; | |
66 int dataNum; | 77 int dataNum; |
78 int idgCount; //number of waiting dataGear | |
67 union Data **data; | 79 union Data **data; |
68 }; | 80 }; |
69 | 81 |
70 union Data { | 82 union Data { |
71 struct Meta { | 83 struct Meta { |
72 enum DataType type; | 84 enum DataType type; |
85 long size; | |
73 struct Queue* wait; // tasks waiting this dataGear | 86 struct Queue* wait; // tasks waiting this dataGear |
74 } meta; | 87 } meta; |
75 struct Context context; | 88 struct Context context; |
76 struct Time { | 89 struct Time { |
77 enum Code next; | 90 enum Code next; |
110 struct CPUWorker { | 123 struct CPUWorker { |
111 pthread_t thread; | 124 pthread_t thread; |
112 struct Context* context; | 125 struct Context* context; |
113 int id; | 126 int id; |
114 struct Queue* tasks; | 127 struct Queue* tasks; |
115 int runFlag; | |
116 enum Code next; | |
117 } CPUWorker; | 128 } CPUWorker; |
118 #ifdef USE_CUDA | 129 #ifdef USE_CUDA |
119 struct CudaWorker { | 130 struct CudaWorker { |
120 pthread_t thread; | 131 pthread_t thread; |
121 struct Context* context; | 132 struct Context* context; |