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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
266
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
3 #include <stdio.h>
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
4
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
5 Queue* createSingleLinkedQueue(struct Context* context) {
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 272
diff changeset
6 struct Queue* queue = new Queue();
266
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
7 struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue();
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
11 queue->take = C_takeSingleLinkedQueue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
12 queue->put = C_putSingleLinkedQueue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
13 queue->isEmpty = C_isEmptySingleLinkedQueue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
14 queue->clear = C_clearSingleLinkedQueue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
15 return queue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
16 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
17
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
18 void printQueue1(union Data* data) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
19 struct Node* node = &data->Element.data->Node;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
20 if (node == NULL) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
21 printf("NULL");
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
22 } else {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
23 printf("key = %d ,", node->key);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
24 printQueue1((union Data*)data->Element.next);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
25 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
26 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
27
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
28 void printQueue(union Data* data) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
29 printQueue1(data);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
30 printf("\n");
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
31 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
32
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
33 __code clearSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...)) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
34 queue->top = NULL;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
35 goto next(...);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
36 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
37
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
38 __code putSingleLinkedQueue(struct SingleLinkedQueue* queue, union Data* data, __code next(...)) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
44 goto next(...);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
45 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
46
272
mir3636
parents: 266
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
55 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
56 goto next(data, ...);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
57 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
58
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
63 goto next(...);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
64 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
65