Mercurial > hg > GearsTemplate
annotate src/synchronizedQueue/synchronizedQueueForCas.c @ 63:2a40d697bf4e
Delete while loop for cas
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 13 Jul 2015 23:20:31 +0900 |
parents | 4283b87ddbf4 |
children | a870c84acd0e |
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); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 //__code code1(struct Context* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 // context->data[Allocate]->allocate.size = sizeof(struct Element); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 // context->data[Allocate]->allocate.next = Code2; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 // goto meta(context, Allocator); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 //} |
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 __code meta(struct Context* context, enum Code next) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 goto (context->code[next])(context); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 //__code code2(struct Context* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 // context->data[Allocate]->allocate.after_put = Code3; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 // context->data[context->dataNum] -> element.value = 1024; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 // goto meta(context, Sender); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 //} |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
34 __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
|
35 allocate->size = sizeof(long); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
36 allocate->next = Code2; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 goto meta(context, Allocator); |
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 code1_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
41 goto code1(context, &context->data[Allocate]->allocate); |
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 |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
44 __code code2(struct Context* context, long* count) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
45 *count = 0; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 goto meta(context, Code3); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
49 __code code2_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
50 goto code2(context, &context->data[Counter]->count); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
51 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
52 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
53 __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
|
54 allocate->size = sizeof(long); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
55 allocate->next = Code4; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 goto meta(context, Allocator); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
59 __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
|
60 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
|
61 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
62 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
63 __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
|
64 *timeOut = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
65 goto meta(context, Code5); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
66 } |
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 __code code4_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
69 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
|
70 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
71 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
72 __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
|
73 long loop = *count; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
74 if(loop == NUM) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
75 goto meta(context, ThreadExit); |
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 allocate->size = sizeof(struct Element); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
78 allocate->next = Code6; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
79 goto meta(context, Allocator); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
80 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
81 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
82 __code code5_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
83 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
|
84 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
85 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
86 __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
|
87 allocate->after_put = Code5; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
88 allocate->after_fail = Code5; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
89 element->value = (*count)++; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 goto meta(context, Sender); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
93 __code code6_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
94 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
|
95 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
96 |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 __code sender(struct Context* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 goto meta(context, Put); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
101 __code sender_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
102 goto sender(context); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
103 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
104 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
105 __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
|
106 struct Element* last_ds = queue->last; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
107 struct Element* new_ds = element; |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
108 new_ds->next = 0; |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
109 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
|
110 goto (context->code[ContinuePut])(context); |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
111 } |
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
112 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
113 if(queue->first) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
114 last_ds->next = new_ds; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 } else { |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
116 queue->first = new_ds; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 } |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
118 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
|
119 *timeOut = 0; |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
120 queue->count++; |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
121 goto (context->code[next])(context); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
124 __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
|
125 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
|
126 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
128 __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
|
129 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
|
130 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
131 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
132 __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
|
133 if(*timeOut < 1000) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
134 (*timeOut)++; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
135 goto (context->code[Put])(context); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
136 } else { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
137 *timeOut = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
138 // goto error handle |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
139 goto meta(context, allocate->after_fail); |
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 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
|
144 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
|
145 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
146 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
147 __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
|
148 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
|
149 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
150 |
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 __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
|
153 allocate->size = sizeof(long); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
154 allocate->next = Code8; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 goto meta(context, Allocator); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
158 __code code7_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
159 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
|
160 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
161 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
162 __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
|
163 *count = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
164 goto meta(context, Code9); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
165 } |
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 __code code8_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
168 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
|
169 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
170 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
171 __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
|
172 allocate->size = sizeof(long); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
173 allocate->next = Code10; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
174 goto meta(context, Allocator); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
175 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
176 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
177 __code code9_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
178 goto code9(context, &context->data[Allocate]->allocate); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
181 __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
|
182 *timeOut = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
183 goto meta(context, Code11); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
184 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
185 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
186 __code code10_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
187 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
|
188 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
189 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
190 __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
|
191 long loop = *count; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 if(loop == NUM) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 goto meta(context, ThreadExit); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 } |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
195 (*count)++; |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
196 allocate->after_get = Code11; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
197 allocate->after_fail = Code11; |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 goto meta(context, Receiver); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
201 __code code11_stub(struct Context* context) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
202 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
|
203 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
204 |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
205 __code receiver(struct Context* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 goto meta(context, Get); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
209 __code receiver_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
210 goto receiver(context); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
211 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
212 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
213 __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
|
214 struct Element *first_ds = queue->first; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
215 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
|
216 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
|
217 goto (context->code[ContinueGet])(context); |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
218 } |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
219 |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
220 // success CAS |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
221 *timeOut = 0; |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
222 if (first_ds == new_ds) { |
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
223 printf("queue is empty\n"); |
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
224 goto meta(context, Get); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
225 } else { |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
226 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
|
227 queue->count--; |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
228 goto (context->code[next])(context); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
229 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
230 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
231 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
232 __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
|
233 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
|
234 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
235 |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
236 __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
|
237 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
|
238 } |
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 __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
|
241 if(*timeOut < 1000) { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
242 (*timeOut)++; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
243 goto (context->code[Get])(context); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
244 } else { |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
245 *timeOut = 0; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
246 // goto error handle |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
247 goto meta(context, allocate->after_fail); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
248 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
249 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
250 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
251 __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
|
252 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
|
253 } |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
254 |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
255 __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
|
256 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
|
257 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
258 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
259 __code thread_exit(struct Context* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
260 free(context->code); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261 free(context->data); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
262 free(context->heapStart); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263 pthread_exit(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 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
266 __code thread_exit_stub(struct Context* context) { |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
267 goto thread_exit(context); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
268 } |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
269 |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270 void* thread_func(void* context) { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 goto start_code((struct Context*)context, Code1); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 return 0; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
275 void* thread_func2(void* context) { |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
276 goto start_code((struct Context*)context, Code7); |
41
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
277 return 0; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
278 } |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
279 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
280 int main() { |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
281 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
|
282 initSynchronizedQueueContext(context1); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
283 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
|
284 initSynchronizedQueueContext(context2); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
285 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
|
286 initSynchronizedQueueContext(context3); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
287 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
|
288 initSynchronizedQueueContext(context4); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
289 context2->data[Queue] = context1->data[Queue]; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
290 context3->data[Queue] = context1->data[Queue]; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
291 context4->data[Queue] = context1->data[Queue]; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
292 |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293 // thread |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294 pthread_t thread1, thread2, thread3, thread4; |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
295 pthread_create(&thread1, NULL, thread_func, (void *)context1); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
296 pthread_create(&thread2, NULL, thread_func, (void *)context2); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
297 pthread_create(&thread3, NULL, thread_func2, (void *)context3); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
298 pthread_create(&thread4, NULL, thread_func2, (void *)context4); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
299 pthread_join(thread1, NULL); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
300 pthread_join(thread2, NULL); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
301 pthread_join(thread3, NULL); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
302 pthread_join(thread4, NULL); |
4a16cbaab802
Add synchronizedQueue for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
303 } |