comparison src/parallel_execution/main.c @ 127:a574ba0da60f

add comment rb_tree
author ikkun
date Wed, 14 Sep 2016 20:43:37 +0900
parents f57e9ffa7960 0f0459653d77
children 337fdbffa693
comparison
equal deleted inserted replaced
126:f57e9ffa7960 127:a574ba0da60f
12 int split = 8; 12 int split = 8;
13 int* array_ptr; 13 int* array_ptr;
14 14
15 void print_queue(struct Element* element) { 15 void print_queue(struct Element* element) {
16 while (element) { 16 while (element) {
17 printf("%d\n", element->task->key); 17 printf("%d\n", ((struct Task *)(element->data))->key);
18 element = element->next; 18 element = element->next;
19 } 19 }
20 } 20 }
21 21
22 void print_tree(struct Node* node) { 22 void print_tree(struct Node* node) {
50 50
51 __code code2(struct Context* context, struct Array* array, struct LoopCounter* loopCounter) { 51 __code code2(struct Context* context, struct Array* array, struct LoopCounter* loopCounter) {
52 int i = loopCounter->i; 52 int i = loopCounter->i;
53 53
54 if (i < length) { 54 if (i < length) {
55 // printf("%d\n", array->array[i]); 55 //printf("%d\n", array->array[i]);
56 if (array->array[i] == (i*2)) { 56 if (array->array[i] == (i*2)) {
57 loopCounter->i++; 57 loopCounter->i++;
58 goto meta(context, Code2); 58 goto meta(context, Code2);
59 } else 59 } else
60 puts("wrong result"); 60 puts("wrong result");
127 __code createTask2_stub(struct Context* context) { 127 __code createTask2_stub(struct Context* context) {
128 goto createTask2(context, &context->data[Allocate]->allocate); 128 goto createTask2(context, &context->data[Allocate]->allocate);
129 } 129 }
130 130
131 __code createTask3(struct Context* context, struct Allocate* allocate) { 131 __code createTask3(struct Context* context, struct Allocate* allocate) {
132 allocate->size = sizeof(struct OdsQueue); 132 allocate->size = sizeof(struct Queue);
133 allocator(context); 133 allocator(context);
134 goto meta(context, CreateTask4); 134 goto meta(context, CreateTask4);
135 } 135 }
136 136
137 __code createTask3_stub(struct Context* context) { 137 __code createTask3_stub(struct Context* context) {
141 __code meta_createTask4(struct Context* context, struct Queue* activeQueue, enum Code next) { 141 __code meta_createTask4(struct Context* context, struct Queue* activeQueue, enum Code next) {
142 context->data[Queue] = (union Data *)activeQueue; 142 context->data[Queue] = (union Data *)activeQueue;
143 goto (context->code[next])(context); 143 goto (context->code[next])(context);
144 } 144 }
145 145
146 __code createTask4(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Queue* waitMe, struct OdsQueue* waitI, struct Element* element, struct Queue* activeQueue) { 146 __code createTask4(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Queue* waitMe, struct Queue* waitI, struct Element* element, struct Queue* activeQueue) {
147 int i = loopCounter->i; 147 int i = loopCounter->i;
148 148
149 waitMe->first = 0; 149 waitMe->first = 0;
150 waitMe->last = 0; 150 waitMe->last = 0;
151 waitMe->count = 0; 151 waitMe->count = 0;
158 task->key = i; 158 task->key = i;
159 task->waitMe = waitMe; 159 task->waitMe = waitMe;
160 task->waitI = waitI; 160 task->waitI = waitI;
161 task->idsCount = 0; 161 task->idsCount = 0;
162 162
163 element->task = task; 163 element->data = (union Data *)task;
164 164
165 context->next = CreateData1; 165 context->next = CreateData1;
166 loopCounter->i++; 166 loopCounter->i++;
167 167
168 goto meta(context, SpawnTask); 168 goto meta(context, SpawnTask);
171 __code createTask4_stub(struct Context* context) { 171 __code createTask4_stub(struct Context* context) {
172 goto createTask4(context, 172 goto createTask4(context,
173 &context->data[LoopCounter]->loopCounter, 173 &context->data[LoopCounter]->loopCounter,
174 &context->data[context->dataNum-2]->task, 174 &context->data[context->dataNum-2]->task,
175 &context->data[context->dataNum-1]->queue, 175 &context->data[context->dataNum-1]->queue,
176 &context->data[context->dataNum]->odsQueue, 176 &context->data[context->dataNum]->queue,
177 &context->data[Element]->element, 177 &context->data[Element]->element,
178 &context->data[ActiveQueue]->queue); 178 &context->data[ActiveQueue]->queue);
179 } 179 }
180 180
181 181
186 // task->key = i; 186 // task->key = i;
187 // task->waitMe = waitMe; 187 // task->waitMe = waitMe;
188 // task->waitI = waitI; 188 // task->waitI = waitI;
189 // task->idsCount = 1; 189 // task->idsCount = 1;
190 // 190 //
191 // element->task = task; 191 // element->data = (union Data *)task;
192 // 192 //
193 // context->next = CreateData1; 193 // context->next = CreateData1;
194 // loopCounter->i++; 194 // loopCounter->i++;
195 // 195 //
196 // goto meta_createTask2(context, activeQueue, PutQueue1); 196 // goto meta_createTask2(context, activeQueue, PutQueue1);
209 //__code createTask5(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Task* slave, struct Element* element) { 209 //__code createTask5(struct Context* context, struct LoopCounter* loopCounter, struct Task* task, struct Task* slave, struct Element* element) {
210 // int i = loopCounter->i; 210 // int i = loopCounter->i;
211 // 211 //
212 // task->code = TaskB; 212 // task->code = TaskB;
213 // task->key = i; 213 // task->key = i;
214 // element->task = task; 214 // element->data = (union Data *)task;
215 // 215 //
216 // context->next = CreateData1; 216 // context->next = CreateData1;
217 // loopCounter->i++; 217 // loopCounter->i++;
218 // 218 //
219 // goto meta(context, WaitFor1); 219 // goto meta(context, WaitFor1);
235 __code putQueue1_stub(struct Context* context) { 235 __code putQueue1_stub(struct Context* context) {
236 goto putQueue1(context, &context->data[Allocate]->allocate); 236 goto putQueue1(context, &context->data[Allocate]->allocate);
237 } 237 }
238 238
239 __code putQueue2(struct Context* context, struct Element* new_element, struct Element* element, struct Queue* queue) { 239 __code putQueue2(struct Context* context, struct Element* new_element, struct Element* element, struct Queue* queue) {
240 new_element->task = element->task; 240 new_element->data = element->data;
241 241
242 if (queue->first) 242 if (queue->first)
243 goto meta(context, PutQueue3); 243 goto meta(context, PutQueue3);
244 else 244 else
245 goto meta(context, PutQueue4); 245 goto meta(context, PutQueue4);