annotate src/synchronizedQueue/synchronizedQueue.c @ 38:ce9fde200f3e

Add code segment sender & receiver to synchronizedQueue
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Sat, 16 May 2015 02:45:31 +0900
parents 240c045ebab2
children 754c90e96e3d
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
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
21 __code code2(struct Context* context) {
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
22 context->data[Allocate]->allocate.after_put = Code3;
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
23 context->data[context->dataNum] -> element.value = 1024;
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
24 goto meta(context, Sender);
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
25 }
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
26
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
27 __code meta_sender(struct Context* context, enum Code next) {
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
28 goto (context->code[next])(context);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
29 }
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
30
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
31 __code sender(struct Context* context) {
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
32 goto meta(context, Put);
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) {
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
36 context->data[Allocate]->allocate.size = sizeof(struct Element);
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
37 context->data[Allocate]->allocate.next = Code4;
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
38 goto meta(context, Allocator);
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
39 }
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
40
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
41 __code code4(struct Context* context) {
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
42 context->data[Allocate]->allocate.after_put = Code5;
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
43 context->data[context->dataNum] -> element.value = 10;
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
44 goto meta(context, Sender);
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
45 }
30
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
47 __code meta_put(struct Context* context, enum Code next) {
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
48 if(context->data[Queue]->queue.first) {
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
49 context->data[Queue]->queue.last->element.next = context->data[context->dataNum];
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
50 context->data[Queue]->queue.last = context->data[Queue]->queue.last->element.next;
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
51 } else {
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
52 context->data[Queue]->queue.first = context->data[context->dataNum];
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
53 context->data[Queue]->queue.last = context->data[Queue]->queue.first;
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
54 }
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
55 context->data[Queue]->queue.last->element.next = 0;
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
56 goto (context->code[next])(context);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
57 }
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
58
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
59 __code put(struct Context* context) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
60 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
61 }
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
64 __code code5(struct Context* context) {
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
65 context->data[Allocate]->allocate.after_get = Code6;
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
66 goto meta(context, Receiver);
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
67 }
30
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
69 __code meta_receiver(struct Context* context, enum Code next) {
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
70 }
30
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
72 __code receiver(struct Context* context, enum Code next) {
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
73 goto meta(context, Get);
30
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 }
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
76 __code meta_get(struct Context* context, enum Code next) {
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
77 if (context->data[Queue]->queue.first == context->data[Queue]->queue.last) {
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
78 printf("queue is empty\n");
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
79 goto (context->code[Exit])(context);
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
80 }
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
81 printf("Get %d\n", context->data[Queue]->queue.first->element.value);
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
82 context->data[Queue]->queue.first = (context->data[Queue]->queue.first->element.next) ? context->data[Queue]->queue.first->element.next : 0;
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
83 goto (context->code[next])(context);
30
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 }
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
86 __code get(struct Context* context) {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
87 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
88 }
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 __code code6(struct Context* context) {
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
91 goto meta(context, Exit);
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
92 }
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
93
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
94
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
95 int main() {
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
96 struct Context* context1 = (struct Context*)malloc(sizeof(struct Context));
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
97 initSynchronizedQueueContext(context1);
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
98 struct Context* context2 = (struct Context*)malloc(sizeof(struct Context));
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
99 initSynchronizedQueueContext(context2);
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
100 context2->data[Queue] = context1->data[Queue];
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
101 goto start_code(context1, Code1);
30
604135010c3a Add file synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 }