Mercurial > hg > CbC > old > DPP
annotate dpp3.cbc @ 8:a15437a1e94c
Fix tableau3
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 25 Dec 2015 18:41:52 +0900 |
parents | d4bc23cb728b |
children | 35d0358b3fe6 |
rev | line source |
---|---|
0
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 /* |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 ** Program: Dining Philosophors Problem |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 ** Author : Atsuki Shimoji |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 */ |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 #include "dpp3.h" |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 #include "queue.h" |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 __code putdown_fork(PhilsPtr self, TaskPtr current_task) |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 { |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 //printf("%d: putdown_lfork:%d\n", self->id, self->left_fork->id); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 self->right_fork->owner = NULL; |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 self->left_fork->owner = NULL; |
8 | 14 self->next = PickUpLeftFork; |
0
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 goto scheduler(self, current_task); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 } |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 /* |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 __code putdown_lfork(PhilsPtr self, TaskPtr current_task) |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 { |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 //printf("%d: putdown_lfork:%d\n", self->id, self->left_fork->id); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 self->left_fork->owner = NULL; |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 self->next = pickup_lfork; |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 goto scheduler(self, current_task); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 } |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 __code putdown_rfork(PhilsPtr self, TaskPtr current_task) |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 { |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 //printf("%d: putdown_rfork:%d\n", self->id, self->right_fork->id); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 self->right_fork->owner = NULL; |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 self->next = putdown_lfork; |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 goto scheduler(self, current_task); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 } |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 */ |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 __code pickup_rfork(PhilsPtr self, TaskPtr current_task) |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 { |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 if (self->right_fork->owner == NULL) { |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 //printf("%d: pickup_rfork:%d\n", self->id, self->right_fork->id); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 self->right_fork->owner = self; |
8 | 41 self->next = PutDownFork; |
0
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 goto scheduler(self, current_task); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 } else { |
8 | 44 self->next = PickUpRightFork; |
0
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 goto scheduler(self, current_task); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 } |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 } |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 __code pickup_lfork(PhilsPtr self, TaskPtr current_task) |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 { |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 if (self->left_fork->owner == NULL) { |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 //printf("%d: pickup_lfork:%d\n", self->id, self->left_fork->id); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 self->left_fork->owner = self; |
8 | 54 self->next = PickUpRightFork; |
0
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 goto scheduler(self, current_task); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 } else { |
8 | 57 self->next = PickUpLeftFork; |
0
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 goto scheduler(self, current_task); |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 } |
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 } |
8 | 61 |
62 __code eating(PhilsPtr self, TaskPtr current_task) | |
63 { | |
64 printf("%d: eating\n", self->id); | |
65 self->next = PutDownRightFork; | |
66 goto scheduler(self, current_task); | |
67 } | |
68 | |
69 __code putdown_lfork(PhilsPtr self, TaskPtr current_task) | |
70 { | |
71 printf("%d: putdown_lfork:%d\n", self->id, self->left_fork->id); | |
72 self->left_fork->owner = NULL; | |
73 self->next = Thinking; | |
74 goto scheduler(self, current_task); | |
75 } | |
76 | |
77 __code putdown_rfork(PhilsPtr self, TaskPtr current_task) | |
78 { | |
79 printf("%d: putdown_rfork:%d\n", self->id, self->right_fork->id); | |
80 self->right_fork->owner = NULL; | |
81 self->next = PutDownLeftFork; | |
82 goto scheduler(self, current_task); | |
83 } | |
84 __code thinking(PhilsPtr self, TaskPtr current_task) | |
85 { | |
86 printf("%d: thinking\n", self->id); | |
87 self->next = WaitLeftFork; | |
88 goto scheduler(self, current_task); | |
89 } | |
0
d4bc23cb728b
Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 /* end */ |