Mercurial > hg > Gears > GearsAgda
annotate src/synchronizedQueue/synchronizedQueueForCas.c @ 118:32773f506410
remove code stack, add continuation of rotateL/totateR
author | ikkun |
---|---|
date | Mon, 26 Sep 2016 19:54:24 +0900 |
parents | 765ee56d68f1 |
children |
rev | line source |
---|---|
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdlib.h> |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 #include <stdio.h> |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #include "synchronizedQueueContext.h" |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
6 #include "./allocate.h" |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 #include "origin_cs.h" |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 #ifdef CLANG |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 #define _CbC_retrun __return |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 #define _CbC_environment __environment |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 #endif |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 #define NUM 100 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 extern __code initSynchronizedQueueContext(struct Context* context); |
66
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
17 extern void allocator(struct Context* context); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 |
66
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
20 //__code code1(struct Context* context) { |
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
21 // context->data[Allocate]->allocate.size = sizeof(struct Element); |
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
22 // goto code2(context); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 //} |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
25 __code code1(struct Context* context, struct Allocate* allocate) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
26 allocate->size = sizeof(long); |
66
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
27 allocator(context); |
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
28 goto meta(context, Code2); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
31 __code code1_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
32 goto code1(context, &context->data[Allocate]->allocate); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
33 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
34 |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
35 __code code2(struct Context* context, long* count) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
36 *count = 0; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 goto meta(context, Code3); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
40 __code code2_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
41 goto code2(context, &context->data[Counter]->count); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
42 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
43 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
44 __code code3(struct Context* context, struct Allocate* allocate) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
45 allocate->size = sizeof(long); |
66
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
46 allocator(context); |
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
47 goto meta(context, Code4); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
50 __code code3_stub(struct Context* context) { |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
51 goto code3(context, &context->data[Allocate]->allocate); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
52 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
53 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
54 __code code4(struct Context* context, long* timeOut) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
55 *timeOut = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
56 goto meta(context, Code5); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
57 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
58 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
59 __code code4_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
60 goto code4(context, &context->data[TimeOut]->timeOut); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
61 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
62 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
63 __code code5(struct Context* context, long* count, struct Allocate* allocate) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
64 long loop = *count; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
65 if(loop == NUM) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
66 goto meta(context, ThreadExit); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
67 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
68 allocate->size = sizeof(struct Element); |
66
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
69 allocator(context); |
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
70 goto meta(context, Code6); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
71 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
72 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
73 __code code5_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
74 goto code5(context, &context->data[Counter]->count, &context->data[Allocate]->allocate); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
75 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
76 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
77 __code code6(struct Context* context, long* count, struct Allocate* allocate, struct Element* element) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
78 allocate->after_put = Code5; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
79 allocate->after_fail = Code5; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
80 element->value = (*count)++; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 goto meta(context, Sender); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
84 __code code6_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
85 goto code6(context, &context->data[Counter]->count, &context->data[Allocate]->allocate, &context->data[context->dataNum]->element); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
86 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
87 |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 __code sender(struct Context* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 goto meta(context, Put); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
92 __code sender_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
93 goto sender(context); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
94 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
95 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
96 __code meta_put(struct Context* context, struct Allocate* allocate, struct Queue* queue, struct Element* element, long* timeOut, enum Code next) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
97 struct Element* last_ds = queue->last; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
98 struct Element* new_ds = element; |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
99 new_ds->next = 0; |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
100 if(!__sync_bool_compare_and_swap(&queue->last, last_ds, new_ds)) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
101 goto (context->code[ContinuePut])(context); |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
102 } |
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
103 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
104 if(queue->first) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
105 last_ds->next = new_ds; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 } else { |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
107 queue->first = new_ds; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 } |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
109 printf("Put %d\n\n", queue->last->value); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
110 *timeOut = 0; |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
111 queue->count++; |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
112 goto (context->code[next])(context); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
115 __code put(struct Context* context, struct Allocate* allocate, struct Queue* queue, struct Element* element, long* timeOut) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
116 goto meta_put(context, allocate, queue, element, timeOut, allocate->after_put); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
119 __code put_stub(struct Context* context) { |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
120 goto put(context, &context->data[Allocate]->allocate, &context->data[Queue]->queue, &context->data[context->dataNum]->element, &context->data[TimeOut]->timeOut); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
121 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
122 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
123 __code meta_continue_put(struct Context* context, struct Allocate* allocate, long *timeOut) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
124 if(*timeOut < 1000) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
125 (*timeOut)++; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
126 goto (context->code[Put])(context); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
127 } else { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
128 *timeOut = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
129 // goto error handle |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
130 goto meta(context, allocate->after_fail); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
131 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
132 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
133 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
134 __code continue_put(struct Context* context, struct Allocate* allocate, long *timeOut) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
135 goto meta_continue_put(context, allocate, timeOut); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
136 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
137 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
138 __code continue_put_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
139 goto continue_put(context, &context->data[Allocate]->allocate, &context->data[TimeOut]->timeOut); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
140 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
141 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
142 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
143 __code code7(struct Context* context, struct Allocate* allocate) { |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
144 allocate->size = sizeof(long); |
66
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
145 allocator(context); |
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
146 goto meta(context, Code8); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
149 __code code7_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
150 goto code7(context, &context->data[Allocate]->allocate); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
151 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
152 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
153 __code code8(struct Context* context, long* count) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
154 *count = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
155 goto meta(context, Code9); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
156 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
157 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
158 __code code8_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
159 goto code8(context, &context->data[Counter]->count); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
160 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
161 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
162 __code code9(struct Context* context, struct Allocate* allocate) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
163 allocate->size = sizeof(long); |
66
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
164 allocator(context); |
a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
165 goto meta(context, Code10); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
166 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
167 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
168 __code code9_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
169 goto code9(context, &context->data[Allocate]->allocate); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
172 __code code10(struct Context* context, long* timeOut) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
173 *timeOut = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
174 goto meta(context, Code11); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
175 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
176 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
177 __code code10_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
178 goto code10(context, &context->data[TimeOut]->timeOut); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
179 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
180 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
181 __code code11(struct Context* context, long* count, struct Allocate* allocate) { |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
182 long loop = *count; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 if(loop == NUM) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 goto meta(context, ThreadExit); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 } |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
186 (*count)++; |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
187 allocate->after_get = Code11; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
188 allocate->after_fail = Code11; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189 goto meta(context, Receiver); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
192 __code code11_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
193 goto code11(context, &context->data[Counter]->count, &context->data[Allocate]->allocate); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
194 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
195 |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 __code receiver(struct Context* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 goto meta(context, Get); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
200 __code receiver_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
201 goto receiver(context); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
202 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
203 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
204 __code meta_get(struct Context* context, struct Allocate* allocate, struct Queue* queue, long* timeOut, enum Code next) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
205 struct Element *first_ds = queue->first; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
206 struct Element *new_ds = first_ds? first_ds->next : 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
207 if(!__sync_bool_compare_and_swap(&queue->first, first_ds, new_ds)) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
208 goto (context->code[ContinueGet])(context); |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
209 } |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
210 |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
211 // success CAS |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
212 *timeOut = 0; |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
213 if (first_ds == new_ds) { |
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
214 printf("queue is empty\n"); |
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
215 goto meta(context, Get); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216 } else { |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
217 printf(" Get %d\n\n", first_ds->value); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
218 queue->count--; |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
219 goto (context->code[next])(context); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
220 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
222 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
223 __code get(struct Context* context, struct Allocate* allocate, struct Queue* queue, long* timeOut) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
224 goto meta_get(context, allocate, queue, timeOut, allocate->after_get); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
225 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
226 |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
227 __code get_stub(struct Context* context) { |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
228 goto get(context, &context->data[Allocate]->allocate, &context->data[Queue]->queue, &context->data[TimeOut]->timeOut); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
229 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
230 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
231 __code meta_continue_get(struct Context* context, struct Allocate* allocate, long *timeOut) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
232 if(*timeOut < 1000) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
233 (*timeOut)++; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
234 goto (context->code[Get])(context); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
235 } else { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
236 *timeOut = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
237 // goto error handle |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
238 goto meta(context, allocate->after_fail); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
239 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
240 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
241 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
242 __code continue_get(struct Context* context, struct Allocate* allocate, long *timeOut) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
243 goto meta_continue_get(context, allocate, timeOut); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
244 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
245 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
246 __code continue_get_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
247 goto continue_get(context, &context->data[Allocate]->allocate, &context->data[TimeOut]->timeOut); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
248 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
249 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
250 __code thread_exit(struct Context* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
251 free(context->code); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
252 free(context->data); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
253 free(context->heapStart); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254 pthread_exit(0); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
255 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
257 __code thread_exit_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
258 goto thread_exit(context); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
259 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
260 |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261 void* thread_func(void* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 goto start_code((struct Context*)context, Code1); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263 return 0; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 void* thread_func2(void* context) { |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
267 goto start_code((struct Context*)context, Code7); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
268 return 0; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 int main() { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 struct Context* context1 = (struct Context*)malloc(sizeof(struct Context)); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 initSynchronizedQueueContext(context1); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 struct Context* context2 = (struct Context*)malloc(sizeof(struct Context)); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
275 initSynchronizedQueueContext(context2); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276 struct Context* context3 = (struct Context*)malloc(sizeof(struct Context)); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
277 initSynchronizedQueueContext(context3); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
278 struct Context* context4 = (struct Context*)malloc(sizeof(struct Context)); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
279 initSynchronizedQueueContext(context4); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
280 context2->data[Queue] = context1->data[Queue]; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
281 context3->data[Queue] = context1->data[Queue]; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
282 context4->data[Queue] = context1->data[Queue]; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
283 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
284 // thread |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
285 pthread_t thread1, thread2, thread3, thread4; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
286 pthread_create(&thread1, NULL, thread_func, (void *)context1); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
287 pthread_create(&thread2, NULL, thread_func, (void *)context2); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
288 pthread_create(&thread3, NULL, thread_func2, (void *)context3); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
289 pthread_create(&thread4, NULL, thread_func2, (void *)context4); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
290 pthread_join(thread1, NULL); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
291 pthread_join(thread2, NULL); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
292 pthread_join(thread3, NULL); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293 pthread_join(thread4, NULL); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294 } |