Mercurial > hg > GearsTemplate
annotate src/parallel_execution/SingleLinkedQueue.cbc @ 462:8d7e5d48cad3
Running CPU examples
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 20 Dec 2017 22:05:08 +0900 |
parents | 394e38952c80 |
children | ac244346c85d |
rev | line source |
---|---|
266 | 1 #include "../context.h" |
462
8d7e5d48cad3
Running CPU examples
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
399
diff
changeset
|
2 #include "Queue.h" |
266 | 3 #include <stdio.h> |
4 | |
5 Queue* createSingleLinkedQueue(struct Context* context) { | |
280 | 6 struct Queue* queue = new Queue(); |
266 | 7 struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue(); |
8 queue->queue = (union Data*)singleLinkedQueue; | |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
9 singleLinkedQueue->top = new Element(); |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
10 singleLinkedQueue->last = singleLinkedQueue->top; |
266 | 11 queue->take = C_takeSingleLinkedQueue; |
12 queue->put = C_putSingleLinkedQueue; | |
13 queue->isEmpty = C_isEmptySingleLinkedQueue; | |
14 queue->clear = C_clearSingleLinkedQueue; | |
15 return queue; | |
16 } | |
17 | |
18 void printQueue1(union Data* data) { | |
19 struct Node* node = &data->Element.data->Node; | |
20 if (node == NULL) { | |
21 printf("NULL"); | |
22 } else { | |
23 printf("key = %d ,", node->key); | |
24 printQueue1((union Data*)data->Element.next); | |
25 } | |
26 } | |
27 | |
28 void printQueue(union Data* data) { | |
29 printQueue1(data); | |
30 printf("\n"); | |
31 } | |
32 | |
33 __code clearSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...)) { | |
34 queue->top = NULL; | |
35 goto next(...); | |
36 } | |
37 | |
38 __code putSingleLinkedQueue(struct SingleLinkedQueue* queue, union Data* data, __code next(...)) { | |
39 Element* element = new Element(); | |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
40 element->data = data; |
266 | 41 element->next = NULL; |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
42 queue->last->next = element; |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
43 queue->last = element; |
266 | 44 goto next(...); |
45 } | |
46 | |
272 | 47 __code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(union Data* data, ...)) { |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
48 struct Element* top = queue->top; |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
49 struct Element* nextElement = top->next; |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
50 if (queue->top == queue->last) { |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
51 data = NULL; |
266 | 52 } else { |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
53 queue->top = nextElement; |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
54 data = nextElement->data; |
266 | 55 } |
56 goto next(data, ...); | |
57 } | |
58 | |
59 __code isEmptySingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...), __code whenEmpty(...)) { | |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
60 if (queue->top == queue->last) |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
61 goto whenEmpty(...); |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
62 else |
266 | 63 goto next(...); |
64 } | |
65 |