Mercurial > hg > GearsTemplate
annotate src/synchronizedQueue/synchronizedQueueContext.h @ 66:a870c84acd0e
Change synchronizedQueue allocator from __code to Function call
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Sep 2015 15:21:50 +0900 |
parents | 2a40d697bf4e |
children |
rev | line source |
---|---|
45
2e7e66ccb3db
Add synchronizedQueueForSem Files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
1 /* Context definition for synchronized queue 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 | 10 Code4, |
11 Code5, | |
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, |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
14 Code8, |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
15 Code9, |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
16 Code10, |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
17 Code11, |
38
ce9fde200f3e
Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
18 Sender, |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 Put, |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
20 ContinuePut, |
38
ce9fde200f3e
Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
21 Receiver, |
36 | 22 Get, |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
23 ContinueGet, |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
24 ThreadExit, |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 Exit, |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 }; |
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 enum UniqueData { |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 Allocate, |
36 | 30 Queue, |
39
754c90e96e3d
Add synchronizedQueue. it use pthread_mutex_lock, unlock
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
31 Counter, |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
32 TimeOut, |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 }; |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 struct Context { |
36 | 36 int codeNum; |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 __code (**code) (struct Context *); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
38 void* heapStart; |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 void* heap; |
36 | 40 long dataSize; |
41 int dataNum; | |
42 union Data* head; | |
43 union Data** data; | |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 }; |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 union Data { |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 long count; |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
48 long timeOut; |
36 | 49 struct Queue { |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
50 struct Element* first; |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
51 struct Element* last; |
38
ce9fde200f3e
Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
52 int count; |
39
754c90e96e3d
Add synchronizedQueue. it use pthread_mutex_lock, unlock
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
53 pthread_mutex_t mutex; |
52
83ee9c75115a
Add pthread_cond_wait & pthread_cond_signal to synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
48
diff
changeset
|
54 pthread_cond_t cond; |
36 | 55 } queue; |
56 struct Element { | |
57 int value; | |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
58 struct Element* next; |
36 | 59 } element; |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 struct Allocate { |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 long size; |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 enum Code after_put; |
36 | 63 enum Code after_get; |
48
1b71266af056
Add CAS loop to synchronizedQueueForCas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
45
diff
changeset
|
64 enum Code after_fail; |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 } allocate; |
36 | 66 }; |