int main() { InitQ(&RunQ); mutexb = CreateSem(1); mutex1 = CreateSem(1); mutex2 = CreateSem(1); wait = CreateSem(1); start_thread(functionA); start_thread(functionB); start_thread(functionC); run(); return 1; }
TEST_F(Directed, AddDoesntMoveCurrent) { Q RunQ; InitQ(&RunQ); list_value_type items[4]; items[0].data = 1; items[1].data = 2; items[2].data = 3; items[3].data = 4; for(int i = 0; i < 4; ++i) AddQ(&RunQ, items + i); auto old_current = RunQ.curr; AddQ(&RunQ, items+1); ASSERT_TRUE(old_current == RunQ.curr); }
void BFS() { long *a,aa[10],*cur,curr[10],i,j,k,depth; long cx,cy,sx,sy,sign,pos_cur,pos_son,ok,x_pos; Init_Prime(); a=aa; cur=curr; for(i=0;i<_MAX_;i++) T[i].ope=T[i].parent=T[i].step=-1; a[0]=9; cur[0]=-1; for(i=1;i<=9;++i) { a[i]=i; cur[i]=-1;} InitQ(); Push(a); Push(cur); T[0].ope=T[0].parent=T[0].step=0; depth=1; while(true) { Pop(cur); if(cur[0]==-1) { if(IsEmtpy()) return; ++depth; Push(cur); Pop(cur); } Search(cur,pos_cur); cx=(cur[0]-1)%3+1; cy=(cur[0]-1)/3+1; x_pos=cur[0]; for(i=0;i<4;i++) { sx=cx+dx[i]; sy=cy+dy[i]; if(IsOutOfBound(sx,sy)) continue; sign=(sy-1)*3+sx; swap(cur[sign],cur[x_pos],ok); cur[0]=sign; Search(cur,pos_son); if(T[pos_son].ope==-1) { T[pos_son].ope=i; T[pos_son].parent=pos_cur; T[pos_son].step=depth; Push(cur); } swap(cur[sign],cur[x_pos],ok); cur[0]=x_pos; } } }
TEST_F(Directed, TwoQueues) { Q RunQ; InitQ(&RunQ); //Q SemQ; list_value_type items[4]; items[0].data = 1; items[1].data = 2; items[2].data = 3; items[3].data = 4; AddQ(&RunQ, items); AddQ(&RunQ, items+1); AddQ(&RunQ, items+2); AddQ(&RunQ, items+3); std::cout << RunQ << '\n'; }
void SleepISR(int sleep_secs){ q_t tmp_q; InitQ(&tmp_q); pcbs[cur_pid].wake_tick = (sys_tick + sleep_secs * 100); while( !(EmptyQ(&sleep_q)) && (pcbs[sleep_q.q[sleep_q.head]].wake_tick <= pcbs[cur_pid].wake_tick) ){ int tmpPID= DeQ(&sleep_q); EnQ(tmpPID, &tmp_q); } EnQ(cur_pid, &tmp_q); while (!EmptyQ(&sleep_q)){ EnQ(DeQ(&sleep_q), &tmp_q); } while(!EmptyQ(&tmp_q)){ EnQ(DeQ(&tmp_q), &sleep_q); } pcbs[cur_pid].state = SLEEP; cur_pid = -1; }
void SleepISR() { q_t tmp_q; InitQ( &tmp_q ); // empty temp q // calc the future wake_tick of cur_pid pcbs[cur_pid].wake_tick = sys_tick + 100 * pcbs[cur_pid].tf_p->eax; // WHILE sleep_q not empty AND the 1st one in it has a wake_tick <= // wake_tick of cur_pid: move that 1st one from sleep_q to tmp_q while(!EmptyQ(&sleep_q) && pcbs[ sleep_q.q[ sleep_q.head ] ].wake_tick <= pcbs[ cur_pid ].wake_tick ) { EnQ(DeQ(&sleep_q), &tmp_q); // append it to tmp_q } // insertion point is reached as either sleep_q is now empty or the // wake_tick of cur_pid is smaller than the 1st one in the sleep_q EnQ( cur_pid, &tmp_q ); // append cur_pid to tmp_q // append the rest of sleep_q to tmp_q while( ! EmptyQ( &sleep_q ) ) { EnQ( DeQ( &sleep_q ), &tmp_q ); } // update sleep_q with the now ordered tmp_q sleep_q = tmp_q; // assignment allowed for struct type pcbs[cur_pid].state = SLEEP; cur_pid = -1; // need to get a different proc to run now }
TEST_F(Directed, CreateBadCondition) { InitQ(&q); q.head = (list_value_type*)1; RotateQ(&q); }
TEST_F(Directed, RotateEmpty) { InitQ(&q); RotateQ(&q); }
TEST_F(Directed, DeleteEmpty) { InitQ(&q); DelQ(&q); }
TEST_F(Directed, CreateBadCondition) { InitQ(&q); q.head = (list_parameter_t*)1; RotateQ(&q); }