Mercurial > hg > Members > Moririn
annotate src/synchronizedQueue/synchronizedQueue.c @ 37:a1fc4c670150
Add CMakeLists.txt to synchronizedQueue
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 15 May 2015 19:19:31 +0900 |
parents | 240c045ebab2 |
children | ce9fde200f3e |
rev | line source |
---|---|
36 | 1 #include <stdlib.h> |
2 #include <stdio.h> | |
3 | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #include "synchronizedQueueContext.h" |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
36 | 6 #include "allocate.h" |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 #include "origin_cs.h" |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 extern __code initSynchronizedQueueContext(struct Context* context); |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 __code code1(struct Context* context) { |
36 | 12 context->data[Allocate]->allocate.size = sizeof(struct Element); |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 context->data[Allocate]->allocate.next = Code2; |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 goto meta(context, Allocator); |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 } |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 __code meta(struct Context* context, enum Code next) { |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 goto (context->code[next])(context); |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 } |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 |
36 | 21 __code meta_code2(struct Context* context, enum Code next) { |
22 context->data[Queue]->queue.head = context->data[context->dataNum]; | |
23 context->data[Queue]->queue.tail = context->data[Queue]->queue.head; | |
24 context->data[context->dataNum]->element.next = 0; | |
25 goto (context->code[next])(context); | |
26 } | |
27 | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 __code code2(struct Context* context) { |
36 | 29 context->data[context->dataNum] -> element.value = 1024; |
30 context->data[Allocate]->allocate.size = sizeof(struct Element); | |
31 context->data[Allocate]->allocate.next = Code3; | |
32 goto meta_code2(context, Allocator); | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 } |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 __code code3(struct Context* context) { |
36 | 36 context->data[Allocate]->allocate.after_put = Code4; |
37 context->data[context->dataNum] -> element.value = 10; | |
38 goto meta(context, Put); | |
39 } | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 |
36 | 41 __code meta_put(struct Context* context, enum Code next) { |
42 context->data[Queue]->queue.tail->element.next = context->data[context->dataNum]; | |
43 context->data[Queue]->queue.tail = context->data[Queue]->queue.tail->element.next; | |
44 context->data[Queue]->queue.tail->element.next = 0; | |
45 goto (context->code[next])(context); | |
46 } | |
47 | |
48 __code put(struct Context* context) { | |
49 goto meta_put(context, context->data[Allocate]->allocate.after_put); | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 } |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 |
36 | 53 __code meta_traverse(struct Context* context, enum Code next) { |
54 printf("current value in queue is %d\n", context->data[Queue]->queue.current->element.value); | |
55 if (context->data[Queue]->queue.current->element.next) { | |
56 context->data[Queue]->queue.current = context->data[Queue]->queue.current->element.next; | |
57 goto meta_traverse(context, next); | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 } |
36 | 59 goto (context->code[next])(context); |
60 } | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 |
36 | 62 __code traverse(struct Context* context) { |
63 context->data[Queue]->queue.current = context->data[Queue]->queue.head; | |
64 goto meta_traverse(context, context->data[Allocate]->allocate.after_traverse); | |
65 } | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 |
36 | 67 __code code4(struct Context* context) { |
68 context->data[Allocate]->allocate.after_traverse = Code5; | |
69 goto meta(context, Traverse); | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 } |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 |
36 | 73 __code code5(struct Context* context) { |
74 context->data[Allocate]->allocate.after_get = Code6; | |
75 goto meta(context, Get); | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 } |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 |
36 | 78 __code meta_get(struct Context* context, enum Code next) { |
79 if (context->data[Queue]->queue.head == context->data[Queue]->queue.tail) { | |
80 printf("queue is empty\n"); | |
81 goto (context->code[Exit])(context); | |
82 } | |
83 context->data[Queue]->queue.head = (context->data[Queue]->queue.head->element.next) ? context->data[Queue]->queue.head->element.next : 0; | |
84 goto (context->code[next])(context); | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 } |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 |
36 | 87 __code get(struct Context* context) { |
88 goto meta_get(context, context->data[Allocate]->allocate.after_get); | |
89 } | |
90 | |
91 __code code6(struct Context* context) { | |
92 printf("after delete\n"); | |
93 context->data[Allocate]->allocate.after_traverse = Exit; | |
94 goto meta(context, Traverse); | |
95 } | |
96 | |
97 | |
98 int main() { | |
99 struct Context* context = (struct Context*)malloc(sizeof(struct Context)); | |
30
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 initSynchronizedQueueContext(context); |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 goto start_code(context, Code1); |
604135010c3a
Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 } |