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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
1 #include <stdlib.h>
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
2 #include <stdio.h>
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
21 __code meta_code2(struct Context* context, enum Code next) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
22 context->data[Queue]->queue.head = context->data[context->dataNum];
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
23 context->data[Queue]->queue.tail = context->data[Queue]->queue.head;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
24 context->data[context->dataNum]->element.next = 0;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
25 goto (context->code[next])(context);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
26 }
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
29 context->data[context->dataNum] -> element.value = 1024;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
30 context->data[Allocate]->allocate.size = sizeof(struct Element);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
31 context->data[Allocate]->allocate.next = Code3;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
36 context->data[Allocate]->allocate.after_put = Code4;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
37 context->data[context->dataNum] -> element.value = 10;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
38 goto meta(context, Put);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
39 }
30
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
41 __code meta_put(struct Context* context, enum Code next) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
42 context->data[Queue]->queue.tail->element.next = context->data[context->dataNum];
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
43 context->data[Queue]->queue.tail = context->data[Queue]->queue.tail->element.next;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
44 context->data[Queue]->queue.tail->element.next = 0;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
45 goto (context->code[next])(context);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
46 }
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
47
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
48 __code put(struct Context* context) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
53 __code meta_traverse(struct Context* context, enum Code next) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
54 printf("current value in queue is %d\n", context->data[Queue]->queue.current->element.value);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
55 if (context->data[Queue]->queue.current->element.next) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
56 context->data[Queue]->queue.current = context->data[Queue]->queue.current->element.next;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
59 goto (context->code[next])(context);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
60 }
30
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
62 __code traverse(struct Context* context) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
63 context->data[Queue]->queue.current = context->data[Queue]->queue.head;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
64 goto meta_traverse(context, context->data[Allocate]->allocate.after_traverse);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
65 }
30
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
67 __code code4(struct Context* context) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
68 context->data[Allocate]->allocate.after_traverse = Code5;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
73 __code code5(struct Context* context) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
74 context->data[Allocate]->allocate.after_get = Code6;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
78 __code meta_get(struct Context* context, enum Code next) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
79 if (context->data[Queue]->queue.head == context->data[Queue]->queue.tail) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
80 printf("queue is empty\n");
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
81 goto (context->code[Exit])(context);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
82 }
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
83 context->data[Queue]->queue.head = (context->data[Queue]->queue.head->element.next) ? context->data[Queue]->queue.head->element.next : 0;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
87 __code get(struct Context* context) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
88 goto meta_get(context, context->data[Allocate]->allocate.after_get);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
89 }
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
90
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
91 __code code6(struct Context* context) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
92 printf("after delete\n");
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
93 context->data[Allocate]->allocate.after_traverse = Exit;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
94 goto meta(context, Traverse);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
95 }
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
96
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
97
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
98 int main() {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
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 }