annotate src/parallel_execution/SingleLinkedStack.cbc @ 479:b8b412a7670a

Fix segmentation fault if multithread
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 28 Dec 2017 19:51:06 +0900
parents ac244346c85d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
1 #include "../context.h"
468
ac244346c85d Change used interface syntax from #include to #interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 462
diff changeset
2 #interface "Stack.h"
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
3 #include <stdio.h>
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
5 // typedef struct SingleLinkedStack {
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
6 // struct Element* top;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
7 // } SingleLinkedStack;
158
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
8
274
d14eb393023d fix generate_stub
mir3636
parents: 260
diff changeset
9 Stack* createSingleLinkedStack(struct Context* context) {
357
mir3636
parents: 356
diff changeset
10 struct Stack* stack = new Stack();
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
11 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack();
357
mir3636
parents: 356
diff changeset
12 stack->stack = (union Data*)singleLinkedStack;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
13 singleLinkedStack->top = NULL;
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
14 stack->push = C_pushSingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
15 stack->pop = C_popSingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
16 stack->pop2 = C_pop2SingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
17 stack->get = C_getSingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
18 stack->get2 = C_get2SingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
19 stack->isEmpty = C_isEmptySingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
20 stack->clear = C_clearSingleLinkedStack;
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
21 return stack;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
24 void printStack1(union Data* data) {
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
25 struct Node* node = &data->Element.data->Node;
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
26 if (node == NULL) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
27 printf("NULL");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
28 } else {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
29 printf("key = %d ,", node->key);
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
30 printStack1((union Data*)data->Element.next);
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
31 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
32 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
33
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
34 void printStack(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
35 printStack1(data);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
36 printf("\n");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
37 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
38
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
39 __code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) {
145
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
40 stack->top = NULL;
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
41 goto next(...);
145
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
42 }
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
43
442
481fce540daf Fix goto implement method of generate_stub
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 357
diff changeset
44 __code pushSingleLinkedStack(struct SingleLinkedStack* stack, union Data* data, __code next(...)) {
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
45 Element* element = new Element();
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
46 element->next = stack->top;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
47 element->data = data;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
48 stack->top = element;
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
49 goto next(...);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
52 __code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
53 if (stack->top) {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
54 data = stack->top->data;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
55 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
56 } else {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
57 data = NULL;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
58 }
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
59 goto next(data, ...);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
62 __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
63 if (stack->top) {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
64 data = stack->top->data;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
65 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
66 } else {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
67 data = NULL;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
68 }
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
69 if (stack->top) {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
70 data1 = stack->top->data;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
71 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
72 } else {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
73 data1 = NULL;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
74 }
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
75 goto next(data, data1, ...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
76 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
77
154
efef5d4df54f Add normal level and agda code
atton
parents: 150
diff changeset
78
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
79 __code getSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) {
141
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
80 if (stack->top)
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
81 data = stack->top->data;
141
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
82 else
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
83 data = NULL;
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
84 goto next(data, ...);
134
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
85 }
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
86
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
87 __code get2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
88 if (stack->top) {
166
mir3636
parents: 160
diff changeset
89 data = stack->top->data;
mir3636
parents: 160
diff changeset
90 if (stack->top->next) {
mir3636
parents: 160
diff changeset
91 data1 = stack->top->next->data;
mir3636
parents: 160
diff changeset
92 } else {
mir3636
parents: 160
diff changeset
93 data1 = NULL;
mir3636
parents: 160
diff changeset
94 }
mir3636
parents: 160
diff changeset
95 } else {
mir3636
parents: 160
diff changeset
96 data = NULL;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
97 data1 = NULL;
166
mir3636
parents: 160
diff changeset
98 }
mir3636
parents: 160
diff changeset
99 goto next(data, data1, ...);
mir3636
parents: 160
diff changeset
100 }
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
101
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
102 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) {
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
103 if (stack->top)
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
104 goto next(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
105 else
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
106 goto whenEmpty(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
107 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
108
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
109