annotate src/synchronizedQueue/synchronizedQueueContext.h @ 40:46917f503bce

Add thread_join to synchronizedQueue
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Mon, 18 May 2015 15:24:46 +0900
parents 754c90e96e3d
children 2e7e66ccb3db
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: 28
diff changeset
1 /* Context definition for list example */
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
39
754c90e96e3d Add synchronizedQueue. it use pthread_mutex_lock, unlock
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
3 #include <pthread.h>
40
46917f503bce Add thread_join to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
4 #define ALLOCATE_SIZE 1000
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 enum Code {
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 Code1,
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Code2,
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Code3,
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
10 Code4,
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
11 Code5,
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
12 Code6,
39
754c90e96e3d Add synchronizedQueue. it use pthread_mutex_lock, unlock
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
13 Code7,
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 Allocator,
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
15 Sender,
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 Put,
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
17 Receiver,
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
18 Get,
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 Exit,
40
46917f503bce Add thread_join to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
20 ThreadExit,
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 };
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 enum UniqueData {
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 Allocate,
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
25 Queue,
39
754c90e96e3d Add synchronizedQueue. it use pthread_mutex_lock, unlock
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
26 Counter,
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 };
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 struct Context {
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
30 int codeNum;
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 __code (**code) (struct Context *);
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
32 void* heap_start;
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 void* heap;
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
34 long dataSize;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
35 int dataNum;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
36 union Data* head;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
37 union Data** data;
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 };
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 union Data {
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 long count;
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
42 struct Queue {
38
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
43 union Data* first;
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
44 union Data* last;
ce9fde200f3e Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
45 int count;
39
754c90e96e3d Add synchronizedQueue. it use pthread_mutex_lock, unlock
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 38
diff changeset
46 pthread_mutex_t mutex;
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
47 } queue;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
48 struct Element {
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
49 int value;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
50 union Data* next;
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
51 } element;
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 struct Allocate {
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 long size;
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 enum Code next;
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 enum Code after_put;
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
56 enum Code after_get;
28
5d9f74220506 Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 } allocate;
36
240c045ebab2 Add normal queue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
58 };