annotate DPP/tableau3.cbc @ 33:3946f8d26710 draft default tip

add benchmarck/binary-trees
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 09 Apr 2013 16:41:30 +0900
parents 6695c97470f3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /*
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 ** Dining Philosophers Problem's scheduler
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 ** with state developper as a tableau method
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 ** 連絡先: 琉球大学情報工学科 河野 真治
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 **
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 ** このソースのいかなる複写,改変,修正も許諾します。ただし、
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 ** その際には、誰が貢献したを示すこの部分を残すこと。
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 ** 再配布や雑誌の付録などの問い合わせも必要ありません。
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 ** 営利利用も上記に反しない範囲で許可します。
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 ** バイナリの配布の際にはversion messageを保存することを条件とします。
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 ** このプログラムについては特に何の保証もしない、悪しからず。
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 **
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 ** Everyone is permitted to do anything on this program
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 ** including copying, modifying, improving,
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 ** as long as you don't try to pretend that you wrote it.
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 ** i.e., the above copyright notice has to appear in all copies.
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 ** Binary distribution requires original version messages.
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 ** You don't have to ask before copying, redistribution or publishing.
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 */
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include <stdlib.h>
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include <time.h>
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "dpp2.h"
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "queue.h"
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "memory.h"
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #include "state_db.h"
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #include "ltl.h"
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 int NUM_PHILOSOPHER = 5; /* A number of philosophers must be more than 2. */
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
1
6695c97470f3 modify some files.
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
34 #define __environment _CbC_environment
6695c97470f3 modify some files.
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
35 #define __return _CbC_return
6695c97470f3 modify some files.
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
36
6695c97470f3 modify some files.
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
37 //static code (*ret)(int);
6695c97470f3 modify some files.
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
38 static code (*ret)(int, void*);
0
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 static void *env;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 static PhilsPtr phils_list = NULL;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 static int max_step = 100;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 static StateDB state_db;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 static MemoryPtr mem;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 static StateNode st;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 static int always_flag; // for LTL
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 int
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 list_length(TaskPtr list)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 int length;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 TaskPtr t;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 if (!list) return 0;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 t = list->next;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 for (length = 1; t && t != list; length++) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 t = t->next;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 return length;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 TaskPtr
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 get_task(int num, TaskPtr list)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 while (num-- > 0) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 list = list->next;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 return list;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 static TaskIteratorPtr task_iter;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 static int depth,count;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 /*
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 Performe depth frist search
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 Possible task iterleave is generated by TaskIterator
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 (using task ring)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 State are recorded in StateDB
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 all memory fragments are regsitered by add_memory_range()
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 including task queue
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 */
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 code tableau(TaskPtr list)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 StateDB out;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 st.hash = get_memory_hash(mem,0);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 if (lookup_StateDB(&st, &state_db, &out)) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 // found in the state database
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 //printf("found %d\n",count);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 while(!(list = next_task_iterator(task_iter))) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 // no more branch, go back to the previous one
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 TaskIteratorPtr prev_iter = task_iter->prev;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 if (!prev_iter) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 printf("All done count %d\n",count);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 printf("Number of unique states %d\n", state_count());
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 memory_usage();
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 show_result(always_flag);
1
6695c97470f3 modify some files.
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
104 goto ret(0,env);
0
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 //printf("no more branch %d\n",count);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 depth--;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 free_task_iterator(task_iter);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 task_iter = prev_iter;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 // return to previous state
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 // here we assume task list is fixed, we don't have to
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 // recover task list itself
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 restore_memory(task_iter->state->memory);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 //printf("restore list %x next %x\n",(int)list,(int)(list->next));
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 } else {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 // one step further
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 depth++;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 task_iter = create_task_iterator(list,out,task_iter);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 //printf("depth %d count %d\n", depth, count++);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 count++;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 goto list->phils->next(list->phils,list);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 code get_next_task_fifo(TaskPtr list)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 TaskPtr t = list;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 TaskPtr e;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 if (max_step--<0) goto die("Simuration end.");
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 list = list->next;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 goto list->phils->next(list->phils,list);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 code scheduler(PhilsPtr phils, TaskPtr list)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 goto check(&always_flag, phils, list);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 // goto next_next_task_fifo(list);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 code task_entry1(int count, PhilsPtr self, TaskPtr list, TaskPtr last);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 code task_entry2(int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 if (!q) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 goto die("Can't allocate Task\n");
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 } else {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 add_memory_range(q,sizeof(Task),&mem);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 goto enqueue(count, self, list, last, q, task_entry1);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 code task_entry1(int count, PhilsPtr self, TaskPtr list, TaskPtr last)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 StateDB out;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 /*
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 printf("int count %d, PhilsPtr self %x, TaskPtr list %x, TaskPtr last %x\n",
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 count, self, list, last);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 */
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 if (count++ < NUM_PHILOSOPHER) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 self = self->left;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 goto create_queue(count,self,list,last,task_entry2);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 } else {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 // make circular task list
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 last->next = list;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 st.memory = mem;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 st.hash = get_memory_hash(mem,0);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 lookup_StateDB(&st, &state_db, &out);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 task_iter = create_task_iterator(list,out,0);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 // start first task
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 goto list->phils->next(list->phils,list);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 code task_entry0(int count, PhilsPtr self, TaskPtr list, TaskPtr last, TaskPtr q)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 add_memory_range(q,sizeof(Task),&mem);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 goto task_entry1(count, self, q, q);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 code init_final(PhilsPtr self)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 self->right = phils_list;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 phils_list->left = self;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 self->right_fork = phils_list->left_fork;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 always_flag = 1;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 //add_memory_range(&always_flag, sizeof(int), &mem);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 //printf("init all\n");
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 goto create_queue(1, self, 0, 0, task_entry0);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 code init_phils2(PhilsPtr self, int count, int id)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 PhilsPtr tmp_self;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 tmp_self = (PhilsPtr)malloc(sizeof(Phils));
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 if (!tmp_self) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 goto die("Can't allocate Phils\n");
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 self->right = tmp_self;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 tmp_self->id = id;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 tmp_self->right_fork = NULL;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 tmp_self->left_fork = self->right_fork;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 tmp_self->right = NULL;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 tmp_self->left = self;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 tmp_self->next = pickup_lfork;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 add_memory_range(tmp_self,sizeof(Phils),&mem);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 count--;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 id++;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 if (count == 0) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 goto init_final(tmp_self);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 } else {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 goto init_fork2(tmp_self, count, id);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 code init_fork2(PhilsPtr self, int count, int id)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 ForkPtr tmp_fork;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 tmp_fork = (ForkPtr)malloc(sizeof(Fork));
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 if (!tmp_fork) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 goto die("Can't allocate Fork\n");
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 tmp_fork->id = id;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 tmp_fork->owner = NULL;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 self->right_fork = tmp_fork;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 add_memory_range(tmp_fork,sizeof(Fork),&mem);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 goto init_phils2(self, count, id);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 code init_phils1(ForkPtr fork, int count, int id)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 PhilsPtr self;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 self = (PhilsPtr)malloc(sizeof(Phils));
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 if (!self) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 goto die("Can't allocate Phils\n");
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 phils_list = self;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 self->id = id;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 self->right_fork = NULL;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 self->left_fork = fork;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 self->right = NULL;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 self->left = NULL;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 self->next = pickup_lfork;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 add_memory_range(self,sizeof(Phils),&mem);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 count--;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 id++;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 goto init_fork2(self, count, id);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 code init_fork1(int count)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 ForkPtr fork;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 int id = 1;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 fork = (ForkPtr)malloc(sizeof(Fork));
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 if (!fork) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 goto die("Can't allocate Fork\n");
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 fork->id = id;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 fork->owner = NULL;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 add_memory_range(fork,sizeof(Fork),&mem);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 goto init_phils1(fork, count, id);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 code die(char *err)
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 printf("%s\n", err);
1
6695c97470f3 modify some files.
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
281 goto ret(1, env);
0
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 int main(int ac, char *av[])
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 {
1
6695c97470f3 modify some files.
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
286 ret = __return;
6695c97470f3 modify some files.
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
287 env = __environment;
0
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 // srand((unsigned)time(NULL));
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 // srandom((unsigned long)time(NULL));
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 reset_state_count();
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 srandom(555);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 if (ac==2) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 NUM_PHILOSOPHER = atoi(av[1]);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) {
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER );
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 return 1;
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 //printf("number of philosopher = %d\n", NUM_PHILOSOPHER );
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 goto init_fork1(NUM_PHILOSOPHER);
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 }
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
a89b61162c29 add DPP
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 /* end */