annotate src/synchronizedQueue/synchronizedQueueForSemContext.h @ 143:34a7a21edc36

recude stack get using traverse field
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 09 Nov 2016 22:33:16 +0900
parents 2e7e66ccb3db
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Context definition for synchronized queue for sem example */
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <pthread.h>
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #define ALLOCATE_SIZE 1000
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 enum Code {
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 Code1,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Code2,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Code3,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 Code4,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 Code5,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 Code6,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 Code7,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 Allocator,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 Sender,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 Put,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 Receiver,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 Get,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 Exit,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 ThreadExit,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 };
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 enum UniqueData {
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 Allocate,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 Queue,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 Counter,
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 };
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 struct Context {
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 int codeNum;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 __code (**code) (struct Context *);
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 void* heap_start;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 void* heap;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 long dataSize;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 int dataNum;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 union Data* head;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 union Data** data;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 };
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 union Data {
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 long count;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 struct Queue {
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 union Data* first;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 union Data* last;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 struct Sem {
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 volatile int value;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 pthread_mutex_t mutex;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 pthread_cond_t cond;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 } *queue_remain, *queue_count;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 } queue;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 struct Element {
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 int value;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 union Data* next;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 } element;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 struct Allocate {
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 long size;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 enum Code next;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 enum Code after_put;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 enum Code after_get;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 } allocate;
2e7e66ccb3db Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 };