# HG changeset patch # User Yasutaka Higa # Date 1451035195 -32400 # Node ID 4a68716b74887a8d2717cf61235c45d61a826b01 # Parent a04eccfc69ae6e6732ab846c63c8833e9d014a0d Fix tableau diff -r a04eccfc69ae -r 4a68716b7488 dpp.h --- a/dpp.h Fri Dec 25 17:15:49 2015 +0900 +++ b/dpp.h Fri Dec 25 18:19:55 2015 +0900 @@ -4,20 +4,6 @@ #include "dpp_common.h" -typedef struct phils { - int id; - struct fork *right_fork; - struct fork *left_fork; - struct phils *right; - struct phils *left; - __code (*next)(struct phils *); -} Phils, *PhilsPtr; - -typedef struct fork { - int id; - struct phils *owner; -} Fork, *ForkPtr; - extern __code putdown_lfork(PhilsPtr self); extern __code putdown_rfork(PhilsPtr self); extern __code eating(PhilsPtr self); diff -r a04eccfc69ae -r 4a68716b7488 dpp2.cbc --- a/dpp2.cbc Fri Dec 25 17:15:49 2015 +0900 +++ b/dpp2.cbc Fri Dec 25 18:19:55 2015 +0900 @@ -9,52 +9,52 @@ __code putdown_lfork(PhilsPtr self, TaskPtr current_task) { - //printf("%d: putdown_lfork:%d\n", self->id, self->left_fork->id); + printf("%d: putdown_lfork:%d\n", self->id, self->left_fork->id); self->left_fork->owner = NULL; - self->next = thinking; + self->next = Thinking; goto scheduler(self, current_task); } __code putdown_rfork(PhilsPtr self, TaskPtr current_task) { - //printf("%d: putdown_rfork:%d\n", self->id, self->right_fork->id); + printf("%d: putdown_rfork:%d\n", self->id, self->right_fork->id); self->right_fork->owner = NULL; - self->next = putdown_lfork; + self->next = PutDownLeftFork; goto scheduler(self, current_task); } __code eating(PhilsPtr self, TaskPtr current_task) { - //printf("%d: eating\n", self->id); - self->next = putdown_rfork; + printf("%d: eating\n", self->id); + self->next = PutDownRightFork; goto scheduler(self, current_task); } /* waiting for right fork */ __code hungry2(PhilsPtr self, TaskPtr current_task) { - //printf("%d: hungry2\n", self->id); - self->next = pickup_rfork; + printf("%d: hungry2\n", self->id); + self->next = PickUpRightFork; goto scheduler(self, current_task); } /* waiting for left fork */ __code hungry1(PhilsPtr self, TaskPtr current_task) { - //printf("%d: hungry1\n", self->id); - self->next = pickup_lfork; + printf("%d: hungry1\n", self->id); + self->next = PickUpLeftFork; goto scheduler(self, current_task); } __code pickup_rfork(PhilsPtr self, TaskPtr current_task) { if (self->right_fork->owner == NULL) { - //printf("%d: pickup_rfork:%d\n", self->id, self->right_fork->id); + printf("%d: pickup_rfork:%d\n", self->id, self->right_fork->id); self->right_fork->owner = self; - self->next = eating; + self->next = Eating; goto scheduler(self, current_task); } else { - self->next = hungry2; + self->next = WaitRightFork; goto scheduler(self, current_task); } } @@ -62,20 +62,20 @@ __code pickup_lfork(PhilsPtr self, TaskPtr current_task) { if (self->left_fork->owner == NULL) { - //printf("%d: pickup_lfork:%d\n", self->id, self->left_fork->id); + printf("%d: pickup_lfork:%d\n", self->id, self->left_fork->id); self->left_fork->owner = self; - self->next = pickup_rfork; + self->next = PickUpRightFork; goto scheduler(self, current_task); } else { - self->next = hungry1; + self->next = WaitRightFork; goto scheduler(self, current_task); } } __code thinking(PhilsPtr self, TaskPtr current_task) { - //printf("%d: thinking\n", self->id); - self->next = hungry1; + printf("%d: thinking\n", self->id); + self->next = WaitLeftFork; goto scheduler(self, current_task); } diff -r a04eccfc69ae -r 4a68716b7488 dpp2.h --- a/dpp2.h Fri Dec 25 17:15:49 2015 +0900 +++ b/dpp2.h Fri Dec 25 18:19:55 2015 +0900 @@ -3,27 +3,6 @@ #include "dpp_common.h" -struct task; -typedef struct phils { - int id; - struct fork *right_fork; - struct fork *left_fork; - struct phils *right; - struct phils *left; - __code (*next)(struct phils *, struct task *); -} Phils, *PhilsPtr; - -typedef struct fork { - int id; - struct phils *owner; -} Fork, *ForkPtr; - -typedef struct task { - struct task *next; - struct phils *phils; -} Task, *TaskPtr; - - extern __code putdown_lfork(PhilsPtr self, TaskPtr current_task); extern __code putdown_rfork(PhilsPtr self, TaskPtr current_task); extern __code eating(PhilsPtr self, TaskPtr current_task); diff -r a04eccfc69ae -r 4a68716b7488 dpp_common.h --- a/dpp_common.h Fri Dec 25 17:15:49 2015 +0900 +++ b/dpp_common.h Fri Dec 25 18:19:55 2015 +0900 @@ -4,4 +4,34 @@ #include #include +enum Action { + PutDownLeftFork, + PutDownRightFork, + Eating, + WaitLeftFork, + WaitRightFork, + PickUpLeftFork, + PickUpRightFork, + Thinking, +}; + +typedef struct phils { + int id; + struct fork *right_fork; + struct fork *left_fork; + struct phils *right; + struct phils *left; + enum Action next; +} Phils, *PhilsPtr; + +typedef struct fork { + int id; + struct phils *owner; +} Fork, *ForkPtr; + +typedef struct task { + struct task *next; + struct phils *phils; +} Task, *TaskPtr; + #endif diff -r a04eccfc69ae -r 4a68716b7488 main.cbc --- a/main.cbc Fri Dec 25 17:15:49 2015 +0900 +++ b/main.cbc Fri Dec 25 18:19:55 2015 +0900 @@ -39,7 +39,7 @@ tmp_self->left_fork = self->right_fork; tmp_self->right = NULL; tmp_self->left = self; - tmp_self->next = thinking; + tmp_self->next = Thinking; count--; id++; @@ -80,7 +80,7 @@ self->left_fork = fork; self->right = NULL; self->left = NULL; - self->next = thinking; + self->next = Thinking; count--; id++; diff -r a04eccfc69ae -r 4a68716b7488 scheduler.cbc --- a/scheduler.cbc Fri Dec 25 17:15:49 2015 +0900 +++ b/scheduler.cbc Fri Dec 25 18:19:55 2015 +0900 @@ -48,7 +48,34 @@ // list = list->next; list = get_task((random()%list_length(list)+1), list); - goto list->phils->next(list->phils,list); + goto do_action(list->phils,list); +} + +__code do_action(PhilsPtr phils, TaskPtr list) +{ + switch (phils->next) { + case PutDownLeftFork: + goto putdown_lfork(phils, list); + case PutDownRightFork: + goto putdown_rfork(phils, list); + case PickUpLeftFork: + goto pickup_lfork(phils, list); + case PickUpRightFork: + goto pickup_rfork(phils, list); + case Thinking: + goto thinking(phils, list); + case Eating: + goto eating(phils, list); + case WaitRightFork: + goto hungry2(phils, list); + case WaitLeftFork: + goto hungry1(phils, list); + default: + printf("invalid action\n"); + exit(1); + } + __code (*action) (PhilsPtr, TaskPtr) = thinking; + goto action(phils, list); } __code get_next_task_fifo(TaskPtr list) @@ -59,7 +86,7 @@ if (max_step--<0) goto die("Simuration end."); list = list->next; - goto list->phils->next(list->phils,list); + goto do_action(list->phils,list); } __code scheduler(PhilsPtr phils, TaskPtr list) @@ -119,7 +146,7 @@ tmp_self->left_fork = self->right_fork; tmp_self->right = NULL; tmp_self->left = self; - tmp_self->next = thinking; + tmp_self->next = Thinking; count--; id++; @@ -160,7 +187,7 @@ self->left_fork = fork; self->right = NULL; self->left = NULL; - self->next = thinking; + self->next = Thinking; count--; id++; diff -r a04eccfc69ae -r 4a68716b7488 scheduler.h --- a/scheduler.h Fri Dec 25 17:15:49 2015 +0900 +++ b/scheduler.h Fri Dec 25 18:19:55 2015 +0900 @@ -4,5 +4,6 @@ extern struct task * current_task; __code scheduler(PhilsPtr self, TaskPtr task); +extern __code do_action(PhilsPtr, TaskPtr); /* end */ diff -r a04eccfc69ae -r 4a68716b7488 tableau.cbc --- a/tableau.cbc Fri Dec 25 17:15:49 2015 +0900 +++ b/tableau.cbc Fri Dec 25 18:19:55 2015 +0900 @@ -30,7 +30,6 @@ int NUM_PHILOSOPHER = 5; /* A number of philosophers must be more than 2. */ -static __code (*ret)(int); static void *env; static PhilsPtr phils_list = NULL; @@ -41,6 +40,34 @@ static MemoryPtr mem; static StateNode st; +// FIXME +__code do_action(PhilsPtr phils, TaskPtr list) +{ + switch (phils->next) { + case PutDownLeftFork: + goto putdown_lfork(phils, list); + case PutDownRightFork: + goto putdown_rfork(phils, list); + case PickUpLeftFork: + goto pickup_lfork(phils, list); + case PickUpRightFork: + goto pickup_rfork(phils, list); + case Thinking: + goto thinking(phils, list); + case Eating: + goto eating(phils, list); + case WaitRightFork: + goto hungry2(phils, list); + case WaitLeftFork: + goto hungry1(phils, list); + default: + printf("invalid action\n"); + exit(1); + } + __code (*action) (PhilsPtr, TaskPtr) = thinking; + goto action(phils, list); +} + int list_length(TaskPtr list) { @@ -51,7 +78,7 @@ t = list->next; for (length = 1; t && t != list; length++) { - t = t->next; + t = t->next; } return length; } @@ -93,7 +120,7 @@ if (!prev_iter) { printf("All done count %d\n",count); memory_usage(); - goto ret(0); + exit(0); } //printf("no more branch %d\n",count); depth--; @@ -112,7 +139,8 @@ } //printf("depth %d count %d\n", depth, count++); count++; - goto list->phils->next(list->phils,list); + //goto list->phils->next(list->phils,list); + goto do_action(list->phils, list); } __code get_next_task_fifo(TaskPtr list) @@ -123,7 +151,8 @@ if (max_step--<0) goto die("Simuration end."); list = list->next; - goto list->phils->next(list->phils,list); + //goto list->phils->next(list->phils,list); + goto do_action(list->phils, list); } __code scheduler(PhilsPtr phils, TaskPtr list) @@ -163,7 +192,8 @@ lookup_StateDB(&st, &state_db, &out); task_iter = create_task_iterator(list,out,0); // start first task - goto list->phils->next(list->phils,list); + //goto list->phils->next(list->phils,list); + goto do_action(list->phils,list); } } @@ -196,7 +226,7 @@ tmp_self->left_fork = self->right_fork; tmp_self->right = NULL; tmp_self->left = self; - tmp_self->next = thinking; + tmp_self->next = Thinking; add_memory_range(tmp_self,sizeof(Phils),&mem); count--; @@ -239,7 +269,7 @@ self->left_fork = fork; self->right = NULL; self->left = NULL; - self->next = thinking; + self->next = Thinking; add_memory_range(self,sizeof(Phils),&mem); count--; @@ -267,12 +297,11 @@ __code die(char *err) { printf("%s\n", err); - goto ret(1); + exit(1); } int main(int ac, char *av[]) { - ret = __return; env = __environment; // srand((unsigned)time(NULL)); // srandom((unsigned long)time(NULL));