# HG changeset patch # User anatofuz # Date 1562064729 -32400 # Node ID 190dadd8405b6f313e8023ef7402f2cecf7878f0 # Parent 35d0358b3fe6500481268cdd3ff468f5b1688161 Format indent diff -r 35d0358b3fe6 -r 190dadd8405b crc32.c --- a/crc32.c Mon Jul 01 22:18:03 2019 +0900 +++ b/crc32.c Tue Jul 02 19:52:09 2019 +0900 @@ -70,7 +70,7 @@ // in the string, using the lookup table values. while(len-->0) { - ulCRC = (ulCRC >> 8) ^ crc32_table[(ulCRC & 0xFF) ^ *buffer++]; + ulCRC = (ulCRC >> 8) ^ crc32_table[(ulCRC & 0xFF) ^ *buffer++]; } // Exclusive OR the result with the beginning value. return ulCRC ^ 0xffffffff; diff -r 35d0358b3fe6 -r 190dadd8405b memory.c --- a/memory.c Mon Jul 01 22:18:03 2019 +0900 +++ b/memory.c Tue Jul 02 19:52:09 2019 +0900 @@ -97,17 +97,17 @@ cmp_content(MemoryPtr a,MemoryPtr b) { if (a->length != b->length) { - if (a->length > b->length) { - return 1; - } else { - return -1; - } + if (a->length > b->length) { + return 1; + } else { + return -1; + } } if (a->hash == b->hash) { #if MEMORY_REPORT - memcmp_count ++; + memcmp_count ++; #endif - return memcmp(a->body,b->body,a->length); + return memcmp(a->body,b->body,a->length); } else if (a->hash > b->hash) { return 1; } else { @@ -128,7 +128,7 @@ if ((r=cmp_content(a,b))) return r; if (a->adr==b->adr) { - return 0; + return 0; } return (a->adr > b->adr) ? 1 : -1; } @@ -138,20 +138,20 @@ { int r; while(1) { - if ((r=cmp_memory1(a,b))) return r; - if (a->left && b->left) { - if ((r=cmp_memory(a->left,b->left))) return r; - } else if (a->left || b->left) { - return (a->left > b->left)? 1 : -1; - } - if (a->right && b->right) { - a = a->right; b = b->right; - // recursive loop - } else if (a->right || b->right) { - return (a->right > b->right)? 1 : -1; - } else { - return 0; // singleton - } + if ((r=cmp_memory1(a,b))) return r; + if (a->left && b->left) { + if ((r=cmp_memory(a->left,b->left))) return r; + } else if (a->left || b->left) { + return (a->left > b->left)? 1 : -1; + } + if (a->right && b->right) { + a = a->right; b = b->right; + // recursive loop + } else if (a->right || b->right) { + return (a->right > b->right)? 1 : -1; + } else { + return 0; // singleton + } } } @@ -165,8 +165,8 @@ MemoryPtr new = create_memory(m->adr,m->length); void *p = (void *)malloc(m->length); if (!p) { - die_exit("can't alloc memory body"); - return 0; + die_exit("can't alloc memory body"); + return 0; } #if MEMORY_REPORT memory_body += m->length; @@ -199,13 +199,13 @@ restore_memory(MemoryPtr m) { while (m) { - memcpy(m->adr,m->body,m->length); + memcpy(m->adr,m->body,m->length); #if MEMORY_REPORT - restore_count ++; - restore_size += m->length; + restore_count ++; + restore_size += m->length; #endif - if (m->left) restore_memory(m->left); - m = m->right; + if (m->left) restore_memory(m->left); + m = m->right; } } @@ -253,19 +253,19 @@ db = *parent; if (!db) { /* not found */ - if (new_memory && out) { - db = new_memory(m); - db->left = db->right = 0; - *out = *parent = db; - } - return 0; + if (new_memory && out) { + db = new_memory(m); + db->left = db->right = 0; + *out = *parent = db; + } + return 0; } if(!(r = cmp_memory1(m,db))) { /* bingo */ - if (out) { - *out = db; - } - return 1; + if (out) { + *out = db; + } + return 1; } else if (r>0) { parent = &db->left; } else if (r<0) { @@ -296,9 +296,9 @@ cmp_range(MemoryPtr a,MemoryPtr b) { if (a->adr==b->adr) { - if (a->length != b->length) - die_exit("memory range inconsitency"); - return 0; + if (a->length != b->length) + die_exit("memory range inconsitency"); + return 0; } return (a->adr > b->adr) ? 1 : -1; } @@ -313,28 +313,28 @@ db = *parent; if (!db) { /* not found */ - if (out) { - db = create_memory(m->adr, m->length); - *out = *parent = db; - } + if (out) { + db = create_memory(m->adr, m->length); + *out = *parent = db; + } #if MEMORY_REPORT - range_count++; - range_size+=m->length; + range_count++; + range_size+=m->length; #endif - return 0; + return 0; + } + if(!(r = cmp_range(m,db))) { + /* bingo (actually an error) */ + if (out) { + *out = db; } - if(!(r = cmp_range(m,db))) { - /* bingo (actually an error) */ - if (out) { - *out = db; - } - return 1; - } else if (r>0) { - parent = &db->left; - } else if (r<0) { + return 1; + } else if (r>0) { + parent = &db->left; + } else if (r<0) { parent = &db->right; - } - } + } + } /* !NOT REACHED */ } diff -r 35d0358b3fe6 -r 190dadd8405b scheduler.cbc --- a/scheduler.cbc Mon Jul 01 22:18:03 2019 +0900 +++ b/scheduler.cbc Tue Jul 02 19:52:09 2019 +0900 @@ -225,12 +225,12 @@ if (argc == 2) { if (argv[1][0] == '-') { if (argv[1][1] == 'r') { - printf("select random\n"); + printf("select random\n"); get_next_task = get_next_task_random; srandom(time(NULL)); - } else { - printf("FIFO\n"); - get_next_task = get_next_task_fifo; + } else { + printf("FIFO\n"); + get_next_task = get_next_task_fifo; } } } diff -r 35d0358b3fe6 -r 190dadd8405b state_db.c --- a/state_db.c Mon Jul 01 22:18:03 2019 +0900 +++ b/state_db.c Tue Jul 02 19:52:09 2019 +0900 @@ -50,33 +50,33 @@ int r; while(1) { - db = *parent; - if (!db) { + db = *parent; + if (!db) { /* not found */ - if (out) { - db = create_stateDB(); - db->left = db->right = 0; - db->memory = copy_memory(s->memory,&mem_db); - db->hash = s->hash; - state_count0 ++; - *parent = db; - *out = db; - } - return 0; - } - if (s->hash == db->hash) { - r = cmp_memory(s->memory,db->memory); - } else - r = (s->hash > db->hash)? 1 : -1; - if(!r) { - /* bingo */ - if (out) *out = db; - return 1; - } else if (r>0) { - parent = &db->left; - } else if (r<0) { - parent = &db->right; - } + if (out) { + db = create_stateDB(); + db->left = db->right = 0; + db->memory = copy_memory(s->memory,&mem_db); + db->hash = s->hash; + state_count0 ++; + *parent = db; + *out = db; + } + return 0; + } + if (s->hash == db->hash) { + r = cmp_memory(s->memory,db->memory); + } else + r = (s->hash > db->hash)? 1 : -1; + if(!r) { + /* bingo */ + if (out) *out = db; + return 1; + } else if (r>0) { + parent = &db->left; + } else if (r<0) { + parent = &db->right; + } } } diff -r 35d0358b3fe6 -r 190dadd8405b tableau2.cbc --- a/tableau2.cbc Mon Jul 01 22:18:03 2019 +0900 +++ b/tableau2.cbc Tue Jul 02 19:52:09 2019 +0900 @@ -80,7 +80,7 @@ t = list->next; for (length = 1; t && t != list; length++) { - t = t->next; + t = t->next; } return length; } @@ -89,7 +89,7 @@ get_task(int num, TaskPtr list) { while (num-- > 0) { - list = list->next; + list = list->next; } return list; } @@ -116,29 +116,29 @@ if (lookup_StateDB(&st, &state_db, &out)) { // found in the state database //printf("found %d\n",count); - while(!(list = next_task_iterator(task_iter))) { - // no more branch, go back to the previous one - TaskIteratorPtr prev_iter = task_iter->prev; - if (!prev_iter) { - printf("All done count %d\n",count); - memory_usage(); - show_result(always_flag); - exit(0); - } - //printf("no more branch %d\n",count); - depth--; - free_task_iterator(task_iter); - task_iter = prev_iter; - } + while(!(list = next_task_iterator(task_iter))) { + // no more branch, go back to the previous one + TaskIteratorPtr prev_iter = task_iter->prev; + if (!prev_iter) { + printf("All done count %d\n",count); + memory_usage(); + show_result(always_flag); + exit(0); + } + //printf("no more branch %d\n",count); + depth--; + free_task_iterator(task_iter); + task_iter = prev_iter; + } // return to previous state // here we assume task list is fixed, we don't have to // recover task list itself - restore_memory(task_iter->state->memory); + restore_memory(task_iter->state->memory); //printf("restore list %x next %x\n",(int)list,(int)(list->next)); } else { - // one step further - depth++; - task_iter = create_task_iterator(list,out,task_iter); + // one step further + depth++; + task_iter = create_task_iterator(list,out,task_iter); } //printf("depth %d count %d\n", depth, count++); count++; @@ -167,10 +167,10 @@ __code task_entry2(int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q) { if (!q) { - goto die("Can't allocate Task\n"); + goto die("Can't allocate Task\n"); } else { - add_memory_range(q,sizeof(Task),&mem); - goto enqueue(count, self, list, last, q, task_entry1); + add_memory_range(q,sizeof(Task),&mem); + goto enqueue(count, self, list, last, q, task_entry1); } } @@ -183,17 +183,17 @@ */ if (count++ < NUM_PHILOSOPHER) { - self = self->left; - goto create_queue(count,self,list,last,task_entry2); + self = self->left; + goto create_queue(count,self,list,last,task_entry2); } else { - // make circular task list - last->next = list; - st.memory = mem; - st.hash = get_memory_hash(mem,0); - lookup_StateDB(&st, &state_db, &out); - task_iter = create_task_iterator(list,out,0); - // start first task - goto do_action(list->phils,list); + // make circular task list + last->next = list; + st.memory = mem; + st.hash = get_memory_hash(mem,0); + lookup_StateDB(&st, &state_db, &out); + task_iter = create_task_iterator(list,out,0); + // start first task + goto do_action(list->phils,list); } } @@ -221,7 +221,7 @@ tmp_self = (PhilsPtr)malloc(sizeof(Phils)); if (!tmp_self) { - goto die("Can't allocate Phils\n"); + goto die("Can't allocate Phils\n"); } self->right = tmp_self; tmp_self->id = id; @@ -236,9 +236,9 @@ id++; if (count == 0) { - goto init_final(tmp_self); + goto init_final(tmp_self); } else { - goto init_fork2(tmp_self, count, id); + goto init_fork2(tmp_self, count, id); } } @@ -248,7 +248,7 @@ tmp_fork = (ForkPtr)malloc(sizeof(Fork)); if (!tmp_fork) { - goto die("Can't allocate Fork\n"); + goto die("Can't allocate Fork\n"); } tmp_fork->id = id; tmp_fork->owner = NULL; @@ -264,7 +264,7 @@ self = (PhilsPtr)malloc(sizeof(Phils)); if (!self) { - goto die("Can't allocate Phils\n"); + goto die("Can't allocate Phils\n"); } phils_list = self; self->id = id; @@ -288,7 +288,7 @@ fork = (ForkPtr)malloc(sizeof(Fork)); if (!fork) { - goto die("Can't allocate Fork\n"); + goto die("Can't allocate Fork\n"); } fork->id = id; fork->owner = NULL; @@ -311,14 +311,13 @@ srandom(555); if (ac==2) { - NUM_PHILOSOPHER = atoi(av[1]); - if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) { - printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER ); - return 1; - } - printf("number of philosopher = %d\n", NUM_PHILOSOPHER ); + NUM_PHILOSOPHER = atoi(av[1]); + if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) { + printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER ); + return 1; + } + printf("number of philosopher = %d\n", NUM_PHILOSOPHER ); } - goto init_fork1(NUM_PHILOSOPHER); } diff -r 35d0358b3fe6 -r 190dadd8405b tableau3.cbc --- a/tableau3.cbc Mon Jul 01 22:18:03 2019 +0900 +++ b/tableau3.cbc Tue Jul 02 19:52:09 2019 +0900 @@ -82,7 +82,7 @@ t = list->next; for (length = 1; t && t != list; length++) { - t = t->next; + t = t->next; } return length; } @@ -91,7 +91,7 @@ get_task(int num, TaskPtr list) { while (num-- > 0) { - list = list->next; + list = list->next; } return list; } @@ -118,30 +118,30 @@ if (lookup_StateDB(&st, &state_db, &out)) { // found in the state database //printf("found %d\n",count); - while(!(list = next_task_iterator(task_iter))) { - // no more branch, go back to the previous one - TaskIteratorPtr prev_iter = task_iter->prev; - if (!prev_iter) { - printf("All done count %d\n",count); - printf("Number of unique states %d\n", state_count()); - memory_usage(); - show_result(always_flag); - exit(0); - } - //printf("no more branch %d\n",count); - depth--; - free_task_iterator(task_iter); - task_iter = prev_iter; - } - // return to previous state - // here we assume task list is fixed, we don't have to - // recover task list itself - restore_memory(task_iter->state->memory); - //printf("restore list %x next %x\n",(int)list,(int)(list->next)); + while(!(list = next_task_iterator(task_iter))) { + // no more branch, go back to the previous one + TaskIteratorPtr prev_iter = task_iter->prev; + if (!prev_iter) { + printf("All done count %d\n",count); + printf("Number of unique states %d\n", state_count()); + memory_usage(); + show_result(always_flag); + exit(0); + } + //printf("no more branch %d\n",count); + depth--; + free_task_iterator(task_iter); + task_iter = prev_iter; + } + // return to previous state + // here we assume task list is fixed, we don't have to + // recover task list itself + restore_memory(task_iter->state->memory); + //printf("restore list %x next %x\n",(int)list,(int)(list->next)); } else { - // one step further - depth++; - task_iter = create_task_iterator(list,out,task_iter); + // one step further + depth++; + task_iter = create_task_iterator(list,out,task_iter); } //printf("depth %d count %d\n", depth, count++); count++; @@ -171,10 +171,10 @@ __code task_entry2(int count,PhilsPtr self, TaskPtr list,TaskPtr last, TaskPtr q) { if (!q) { - goto die("Can't allocate Task\n"); + goto die("Can't allocate Task\n"); } else { - add_memory_range(q,sizeof(Task),&mem); - goto enqueue(count, self, list, last, q, task_entry1); + add_memory_range(q,sizeof(Task),&mem); + goto enqueue(count, self, list, last, q, task_entry1); } } @@ -187,17 +187,17 @@ */ if (count++ < NUM_PHILOSOPHER) { - self = self->left; - goto create_queue(count,self,list,last,task_entry2); + self = self->left; + goto create_queue(count,self,list,last,task_entry2); } else { // make circular task list - last->next = list; - st.memory = mem; - st.hash = get_memory_hash(mem,0); - lookup_StateDB(&st, &state_db, &out); - task_iter = create_task_iterator(list,out,0); - // start first task - goto do_action(list->phils, list); + last->next = list; + st.memory = mem; + st.hash = get_memory_hash(mem,0); + lookup_StateDB(&st, &state_db, &out); + task_iter = create_task_iterator(list,out,0); + // start first task + goto do_action(list->phils, list); } } @@ -225,7 +225,7 @@ tmp_self = (PhilsPtr)malloc(sizeof(Phils)); if (!tmp_self) { - goto die("Can't allocate Phils\n"); + goto die("Can't allocate Phils\n"); } self->right = tmp_self; tmp_self->id = id; @@ -240,9 +240,9 @@ id++; if (count == 0) { - goto init_final(tmp_self); + goto init_final(tmp_self); } else { - goto init_fork2(tmp_self, count, id); + goto init_fork2(tmp_self, count, id); } } @@ -252,7 +252,7 @@ tmp_fork = (ForkPtr)malloc(sizeof(Fork)); if (!tmp_fork) { - goto die("Can't allocate Fork\n"); + goto die("Can't allocate Fork\n"); } tmp_fork->id = id; tmp_fork->owner = NULL; @@ -268,7 +268,7 @@ self = (PhilsPtr)malloc(sizeof(Phils)); if (!self) { - goto die("Can't allocate Phils\n"); + goto die("Can't allocate Phils\n"); } phils_list = self; self->id = id; @@ -292,7 +292,7 @@ fork = (ForkPtr)malloc(sizeof(Fork)); if (!fork) { - goto die("Can't allocate Fork\n"); + goto die("Can't allocate Fork\n"); } fork->id = id; fork->owner = NULL; @@ -316,11 +316,11 @@ srandom(555); if (ac==2) { - NUM_PHILOSOPHER = atoi(av[1]); - if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) { - printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER ); - return 1; - } + NUM_PHILOSOPHER = atoi(av[1]); + if (NUM_PHILOSOPHER >10 ||NUM_PHILOSOPHER < 2) { + printf("illegal number of philosopher = %d\n", NUM_PHILOSOPHER ); + return 1; + } //printf("number of philosopher = %d\n", NUM_PHILOSOPHER ); }