Mercurial > hg > CbC > old > DPP
changeset 6:4a68716b7488
Fix tableau
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 25 Dec 2015 18:19:55 +0900 |
parents | a04eccfc69ae |
children | 171cc032eb29 |
files | dpp.h dpp2.cbc dpp2.h dpp_common.h main.cbc scheduler.cbc scheduler.h tableau.cbc |
diffstat | 8 files changed, 121 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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); }
--- 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);
--- 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<stdio.h> #include<stdlib.h> +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
--- 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++;
--- 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++;
--- 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 */
--- 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));