Mercurial > hg > GearsTemplate
annotate src/synchronizedQueue/synchronizedQueueContext.c @ 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 |
---|---|
36 | 1 #include <stdlib.h> |
2 | |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 #include "synchronizedQueueContext.h" |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
5 extern __code code1_stub(struct Context*); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
6 extern __code code2_stub(struct Context*); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
7 extern __code code3_stub(struct Context*); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
8 extern __code code4_stub(struct Context*); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
9 extern __code code5_stub(struct Context*); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
10 extern __code code6_stub(struct Context*); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
11 extern __code code7_stub(struct Context*); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
12 extern __code code8_stub(struct Context*); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
13 extern __code code9_stub(struct Context*); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
14 extern __code code10_stub(struct Context*); |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
15 extern __code code11_stub(struct Context*); |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 extern __code meta(struct Context*); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
17 extern __code sender_stub(struct Context*); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
18 extern __code put_stub(struct Context*); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
19 extern __code continue_put_stub(struct Context*); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
20 extern __code receiver_stub(struct Context*); |
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
21 extern __code get_stub(struct Context*); |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
22 extern __code continue_get_stub(struct Context*); |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 extern __code exit_code(struct Context*); |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
24 extern __code thread_exit_stub(struct Context*); |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 |
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 __code initSynchronizedQueueContext(struct Context* context) { |
36 | 27 context->dataSize = sizeof(union Data)*ALLOCATE_SIZE; |
28 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); | |
29 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); | |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
30 context->heapStart = malloc(context->dataSize); |
36 | 31 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
32 context->codeNum = Exit; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
33 context->code[Code1] = code1_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
34 context->code[Code2] = code2_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
35 context->code[Code3] = code3_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
36 context->code[Code4] = code4_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
37 context->code[Code5] = code5_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
38 context->code[Code6] = code6_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
39 context->code[Code7] = code7_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
40 context->code[Code8] = code8_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
41 context->code[Code9] = code9_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
42 context->code[Code10] = code10_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
43 context->code[Code11] = code11_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
44 context->code[Sender] = sender_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
45 context->code[Put] = put_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
46 context->code[ContinuePut] = continue_put_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
47 context->code[Receiver] = receiver_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
48 context->code[Get] = get_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
49 context->code[ContinueGet] = continue_get_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
50 context->code[ThreadExit] = thread_exit_stub; |
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
51 context->code[Exit] = exit_code; |
36 | 52 |
63
2a40d697bf4e
Delete while loop for cas
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
53 context->heap = context->heapStart; |
36 | 54 |
55 context->data[Allocate] = context->heap; | |
56 context->heap += sizeof(struct Allocate); | |
57 | |
58 context->data[Queue] = context->heap; | |
59 context->heap += sizeof(struct Queue); | |
38
ce9fde200f3e
Add code segment sender & receiver to synchronizedQueue
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
60 context->data[Queue]->queue.first = 0; |
39
754c90e96e3d
Add synchronizedQueue. it use pthread_mutex_lock, unlock
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
61 pthread_mutex_init(&context->data[Queue]->queue.mutex, NULL); |
52
83ee9c75115a
Add pthread_cond_wait & pthread_cond_signal to synchronizedQueue.c
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
62 pthread_cond_init(&context->data[Queue]->queue.cond, NULL); |
36 | 63 |
64 context->dataNum = Queue; | |
28
5d9f74220506
Add file synchronizedQueueContext
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 } |