annotate scheduler.cbc @ 2:b15128ab0324

Fix dpp2 for cbc using LLVM 3.7
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Wed, 16 Dec 2015 17:16:29 +0900
parents d4bc23cb728b
children 6bf69a0f2e24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ** Dining Philosophers Problem's scheduler
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 */
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <stdio.h>
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <stdlib.h>
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include <time.h>
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include "dpp2.h"
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include "queue.h"
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #define NUM_PHILOSOPHER 5 /* A number of philosophers must be more than 2. */
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
12 __code (*ret)(int);
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 void *env;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
15 __code (*get_next_task)(TaskPtr);
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 PhilsPtr phils_list = NULL;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 int id = 1; /* This is a counter variable to detect a process. */
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 static int max_step = 100;
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 /* 環状リストでもlengthを返す */
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 int list_length(TaskPtr list)
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 int length;
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
25 TaskPtr q;
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 if (!list) return 0;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 q = list->next;
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 for (length = 1; q && q != list; length++) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 q = q->next;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 return length;
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 TaskPtr get_task(int num, TaskPtr list)
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 while (num-- > 0) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 list = list->next;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 return list;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
43 __code get_next_task_random(TaskPtr list)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 TaskPtr t = list;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 TaskPtr e;
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 if (max_step--<0) goto die("Simuration end.");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 // list = list->next;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 list = get_task((random()%list_length(list)+1), list);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 goto list->phils->next(list->phils,list);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
55 __code get_next_task_fifo(TaskPtr list)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 TaskPtr t = list;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 TaskPtr e;
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 if (max_step--<0) goto die("Simuration end.");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 list = list->next;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 goto list->phils->next(list->phils,list);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
66 __code scheduler(PhilsPtr phils, TaskPtr list)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 goto get_next_task(list);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
71 __code task_entry1(int count, PhilsPtr self, TaskPtr list, TaskPtr last);
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
73 __code task_entry2(int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 if (!q) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 goto die("Can't allocate Task\n");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 } else {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 goto enqueue(count, self, list, last, q, task_entry1);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
82 __code task_entry1(int count, PhilsPtr self, TaskPtr list, TaskPtr last)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 printf("int count %d, PhilsPtr self %x, TaskPtr list %x, TaskPtr last %x\n",
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 count, self, list, last);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 if (count++ < NUM_PHILOSOPHER) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 self = self->left;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 goto create_queue(count,self,list,last,task_entry2);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 } else {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 last->next = list;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 goto scheduler(list->phils,list);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
96 __code task_entry0(int count, PhilsPtr self, TaskPtr list, TaskPtr last, TaskPtr q)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 goto task_entry1(count, self, q, q);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
101 __code init_final(PhilsPtr self)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 self->right = phils_list;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 self->right_fork = phils_list->left_fork;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 printf("init all\n");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 goto create_queue(1, self, 0, 0, task_entry0);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
110 __code init_phils2(PhilsPtr self, int count, int id)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 PhilsPtr tmp_self;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 tmp_self = (PhilsPtr)malloc(sizeof(Phils));
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 if (!tmp_self) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 goto die("Can't allocate Phils\n");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 self->right = tmp_self;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 tmp_self->id = id;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 tmp_self->right_fork = NULL;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 tmp_self->left_fork = self->right_fork;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 tmp_self->right = NULL;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 tmp_self->left = self;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 tmp_self->next = thinking;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 count--;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 id++;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 if (count == 0) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 goto init_final(tmp_self);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 } else {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 goto init_fork2(tmp_self, count, id);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
136 __code init_fork2(PhilsPtr self, int count, int id)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 ForkPtr tmp_fork;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 tmp_fork = (ForkPtr)malloc(sizeof(Fork));
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 if (!tmp_fork) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 goto die("Can't allocate Fork\n");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 tmp_fork->id = id;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 tmp_fork->owner = NULL;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 self->right_fork = tmp_fork;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 goto init_phils2(self, count, id);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
151 __code init_phils1(ForkPtr fork, int count, int id)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 PhilsPtr self;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 self = (PhilsPtr)malloc(sizeof(Phils));
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 if (!self) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 goto die("Can't allocate Phils\n");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 phils_list = self;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 self->id = id;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 self->right_fork = NULL;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 self->left_fork = fork;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 self->right = NULL;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 self->left = NULL;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 self->next = thinking;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 count--;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 id++;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 goto init_fork2(self, count, id);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
173 __code init_fork1(int count)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 ForkPtr fork;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 int id = 1;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 fork = (ForkPtr)malloc(sizeof(Fork));
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 if (!fork) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 goto die("Can't allocate Fork\n");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 fork->id = id;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 fork->owner = NULL;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 goto init_phils1(fork, count, id);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
188 __code die(char *err)
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 printf("%s\n", err);
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
191 goto ret(1);
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 int main(int argc, char **argv)
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 {
2
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
196 ret = __return;
b15128ab0324 Fix dpp2 for cbc using LLVM 3.7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
197 env = __environment;
0
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 // srand((unsigned)time(NULL));
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 // srandom((unsigned long)time(NULL));
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 get_next_task = get_next_task_fifo;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 if (argc == 2) {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 if (argv[1][0] == '-') {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 if (argv[1][1] == 'r') {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 printf("select random\n");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 get_next_task = get_next_task_random;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 srandom(time(NULL));
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 } else {
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 printf("FIFO\n");
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 get_next_task = get_next_task_fifo;
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 goto init_fork1(NUM_PHILOSOPHER);
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 }
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
d4bc23cb728b Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 /* end */