Mercurial > hg > CbC > old > DPP
diff tableau.cbc @ 6:4a68716b7488
Fix tableau
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 25 Dec 2015 18:19:55 +0900 |
parents | 6bf69a0f2e24 |
children | 35d0358b3fe6 |
line wrap: on
line diff
--- 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));