/* Cria e envia uma trama do tipo type (Não funcional para tipo I) */ int buildFrame(int flag, char * type) { info->frameSend[0] = F; if (type == "set") info->frameSend[2] = C_SET; else if (type == "ua") info->frameSend[2] = C_UA; else if (type == "disc") info->frameSend[2] = C_DISC; else if (!strcmp(type, "rr1")) info->frameSend[2] = RR(1); else if (!strcmp(type,"rr0")) info->frameSend[2] = RR(0); else if (!strcmp(type,"rej0")) info->frameSend[2] = REJ(0); else if (!strcmp(type,"rej1")) info->frameSend[2] = REJ(0); else return 0; info->frameSend[1] = campo_endereco(info->flag, info->frameSend[2]); info->frameSend[3] = info->frameSend[1]^info->frameSend[2]; info->frameSend[4] = F; info->frameSendLength = 5; //printf("Trama composta %s: 0x%x 0x%x 0x%x 0x%x 0x%x \n", type, info->frameSend[0], info->frameSend[1], info->frameSend[2], info->frameSend[3], info->frameSend[4]); return 1; }
static int pg_wait( int unit, int go, int stop, int tmo, char * msg ) { int j, r, e, s, p; PG.status = 0; j = 0; while ((((r=RR(1,6))&go)||(stop&&(!(r&stop))))&&(time_before(jiffies,tmo))) { if (j++ < PG_SPIN) udelay(PG_SPIN_DEL); else pg_sleep(1); } if ((r&(STAT_ERR&stop))||time_after_eq(jiffies, tmo)) { s = RR(0,7); e = RR(0,1); p = RR(0,2); if (verbose > 1) printk("%s: %s: stat=0x%x err=0x%x phase=%d%s\n", PG.name,msg,s,e,p,time_after_eq(jiffies, tmo)?" timeout":""); if (time_after_eq(jiffies, tmo)) e |= 0x100; PG.status = (e >> 4) & 0xff; return -1; }
int main(void) { Job in[N]; Job jobs[N]; int cnt = 0; while (scanf("%s%d%d", in[cnt].name, &in[cnt].arrive_time, &in[cnt].serve_time) == 3) cnt++; copy(jobs, in, cnt); printf("FCFS\n"); FCFS(jobs, cnt); display(jobs, cnt); copy(jobs, in, cnt); printf("RR-1\n"); RR(jobs, cnt, 1); display(jobs, cnt); copy(jobs, in, cnt); printf("RR-4\n"); RR(jobs, cnt, 4); display(jobs, cnt); copy(jobs, in, cnt); printf("SJF\n"); SJF(jobs, cnt); display(jobs, cnt); copy(jobs, in, cnt); printf("HRN\n"); HRN(jobs, cnt); display(jobs, cnt); return 0; }
tmpl(uint32_t)::get_absolute_dest_reg(ins_t ins) const { switch(ins.call.op) { case 0 : { // Format2 instruction : sethi, branch, branch_fp, branch_cp, unimp or garbage... if (ins.branches.op2 == 4) // SETHI return RR(ins.sethi.rd); else return 0; break; } case 1 : // This is a format1 instruction : CALL return 0; break; case 2 : case 3 : // This is one of the logical instructions (format3) return RR(ins.format3.rd); break; } return 0; }
static void dss_restore_context(void) { RR(SYSCONFIG); RR(CONTROL); RR(SDI_CONTROL); RR(PLL_CONTROL); }
/** * Function ReFillRender * Rebuild Render for instance after the config is read */ void GERBER_LAYER_WIDGET::ReFillRender() { ClearRenderRows(); // Fixed "Rendering" tab rows within the LAYER_WIDGET, only the initial color // is changed before appending to the LAYER_WIDGET. This is an automatic variable // not a static variable, change the color & state after copying from code to renderRows // on the stack. LAYER_WIDGET::ROW renderRows[3] = { #define RR LAYER_WIDGET::ROW // Render Row abreviation to reduce source width // text id color tooltip checked RR( _( "Grid" ), GERBER_GRID_VISIBLE, WHITE, _( "Show the (x,y) grid dots" ) ), RR( _( "DCodes" ), DCODES_VISIBLE, WHITE, _( "Show DCodes identification" ) ), RR( _( "Neg. Obj." ), NEGATIVE_OBJECTS_VISIBLE, DARKGRAY, _( "Show negative objects in this color" ) ), }; for( unsigned row=0; row<DIM(renderRows); ++row ) { if( renderRows[row].color != -1 ) // does this row show a color? { renderRows[row].color = myframe->GetVisibleElementColor( (GERBER_VISIBLE_ID)renderRows[row].id ); } renderRows[row].state = myframe->IsElementVisible( (GERBER_VISIBLE_ID)renderRows[row].id ); } AppendRenderRows( renderRows, DIM(renderRows) ); }
/* retorna o tipo de frame verificando o campo de controlo */ char * verifyFrameType(char * frame) { switch(frame[2]) { case C_SET: return "set"; break; case C_DISC: return "disc"; break; case C_UA: return "ua"; break; case RR(1): return "rr1"; break; case RR(0): return "rr0"; break; case REJ(0): return "rej0"; break; case REJ(1): return "rej1"; break; case C_I0: return "I0"; break; case C_I1: return "I1"; break; } }
void dss_restore_context(void) { if (_omap_dss_wait_reset()) DSSERR("DSS not coming out of reset after sleep\n"); RR(SYSCONFIG); RR(CONTROL); #ifdef CONFIG_OMAP2_DSS_SDI RR(SDI_CONTROL); RR(PLL_CONTROL); #endif }
RR orderstats(const vector<double>& binomCoeff, vector<double>& sigs){ int numLayers = sigs.size(); //First we sort them double tmp; bool changed = true; while(changed){ changed = false; for(int i=0; i<numLayers-1; i++){ if(sigs[i]<sigs[i+1]){ tmp = sigs[i]; sigs[i] = sigs[i+1]; sigs[i+1] = tmp; changed = true; } } } vector<RR> ordersigs; RR sqr2(2); sqr2 = sqrt(sqr2); ordersigs.resize(numLayers); try{ for(int i=0; i<numLayers; i++){ ordersigs[i] = sigs[i]; ordersigs[i] = RR(0.5) * erfc(ordersigs[i] / sqr2); //We find the cumulative distribution of each } }catch(const std::exception& e) { std::cout << "\n""Message from thrown exception was:\n " << e.what() << std::endl; } for(int i=0; i<numLayers; i++){ RR sum(0.0); for(int j= i+1; j<=numLayers; j++){ sum += RR(binomCoeff[j]) * pow(ordersigs[i], j) * pow(1.0-ordersigs[i],numLayers-j); } ordersigs[i] = sum; } int min = 0; for(int i=1; i<numLayers; i++){ if(ordersigs[i] < ordersigs[min]){ min = i; } } return ordersigs[min]; }
/* Insert sessid and socket pair in AVL Tree */ AVLTree_Node* insertion(AVLTree_Node *T,uint16_t x, struct node *head) { if(T==NULL) { T=(AVLTree_Node*)malloc(sizeof(AVLTree_Node)); T->data=x; T->head = head; T->left=NULL; T->right=NULL; } else if(x > T->data) // insert in right subtree { T->right=insertion(T->right,x,head); if(BF(T)==-2) if(x>T->right->data) T=RR(T); else T=RL(T); } else if(x<T->data) { T->left=insertion(T->left,x,head); if(BF(T)==2) if(x < T->left->data) T=LL(T); else T=LR(T); } T->ht=height(T); //root=T; return(T); }
int main() { int ch, size, burstTime[MAX], flag = 1,i; printf("Enter the number of processes : \n"); scanf("%d",&size); printf("Enter the burst time for each process P\n"); for (i = 0; i < size; ++i) scanf("%d", &burstTime[i]); printf("Enter the choice of implementation of CPU Scheduling Algorithm :\n"); menu(); while(flag) { scanf("%d",&ch); switch(ch) { case 1 : FCFS(burstTime, size); break; // case 2 : SJF(burstTime, size); // break; case 3 : RR(burstTime, size); break; default : flag = 0; continue; } } printf("Thank You for using the program.\n"); }
avltree insert(avltree root,Elemtype data) { if(!root) { root=(pnode)malloc(sizeof(node)); root->data=data; root->left=root->right=0; root->height=0; } else if(data < root->data) //插到左边 { root->left=insert(root->left,data); if(HEIGHT(root->left)-HEIGHT(root->right)==2) //失去平衡 { if(data < root->left->data) root=LL(root); else root=LR(root); } } else if(data >root->data) //插到右边 { root->right=insert(root->right,data); if(HEIGHT(root->right)-HEIGHT(root->left)==2) //失去平衡 { if(data > root->right->data) root=RR(root); else root=RL(root); } } //data在树中已存在时什么事也不做 root->height=MAX(HEIGHT(root->left),HEIGHT(root->right))+1; return root; }
Eximpl int /* 0 | depth */ epd_get_dep_prog( EpdJob* ejp, int dftdep ) { /* * If |ce| > 32000 --> either normal with depth or prove lost with depth * If dm > 0 --> normal with depth * If pv ends in # --> normal or lost with depth * |ce| >> 0 --> normal or lost with default depth * else: Try normal and lost, default depth * FFS: jobtype other than normal? * We derive a depth, and a "jobprog", or fail. */ int ce; int plies; int dm; int pv; #define RR(dep, prog) { f_jobprog = (prog); return (dep); } ce = epd_op_numval(ejp, "ce"); dm = epd_op_numval(ejp, "dm"); pv = epd_pv_plies(ejp); if( ce > 32000 ) { /* ce = 32767 - plies; plies = 32767 - ce * plies = 2D-1; plies+1 = 2D; D = (plies+1)/2 */ plies = 32767 - ce; if( (plies > 0) && (plies % 2) ) { RR( (plies+1)/2, JTP__normal ) } }else if( ce < -32000 ) {
static void epat_log_adapter( PIA *pi, char * scratch, int verbose ) { int ver; char *mode_string[6] = {"4-bit","5/3","8-bit","EPP-8","EPP-16","EPP-32"}; epat_connect(pi); WR(0xa,0x38); /* read the version code */ ver = RR(0xb); epat_disconnect(pi); #ifdef CONFIG_DEBUG_PRINTK printk("%s: epat %s, Shuttle EPAT chip %x at 0x%x, ", pi->device,EPAT_VERSION,ver,pi->port); #else ; #endif #ifdef CONFIG_DEBUG_PRINTK printk("mode %d (%s), delay %d\n",pi->mode, mode_string[pi->mode],pi->delay); #else ; #endif }
static Node RL(Node rootnode){ printf("do a RL in node %d\n" , rootnode -> data); rootnode -> right = LL(rootnode -> right); return RR(rootnode); }
//right left situation static TLDNode *RL(TLDNode *node){ TLDNode *temp; temp=node->right; //perform rotation node->right=LL(temp); return RR(node); }
static Node LR(Node rootnode){ printf("do a LR in node %d\n" , rootnode -> data); rootnode -> left = RR(rootnode -> left); return LL(rootnode); }
node *insertNode(node *root, int cont){ if(root==NULL){ return createNode(cont); } else if(cont>root->data) { root->right=insertNode(root->right,cont); if(BF(root)==-2){ if(cont>root->right->data) root=RR(root); else root=RL(root); } } else if(cont<root->data) { root->left=insertNode(root->left,cont); if(BF(root)==2){ if(cont < root->left->data) root=LL(root); else root=LR(root); } } /*else{ if(cont==root->data) printf("the node %d already exists in the tree",cont); return root; }*/ root->ht=height(root); return(root); }
node * insert(node *T,int x) { if(T==NULL) { T=(node*)malloc(sizeof(node)); T->data=x; T->left=NULL; T->right=NULL; } else if(x > T->data) // insert in right subtree { T->right=insert(T->right,x); if(BF(T)==-2) if(x>T->right->data) T=RR(T); else T=RL(T); } else if(x<T->data) { T->left=insert(T->left,x); if(BF(T)==2) if(x < T->left->data) T=LL(T); else T=LR(T); } T->ht=height(T); return(T); }
void GEMENI_charsent() { unsigned long r = s->log[s->lc]; if (UCA0IFG & UCTXIFG) { s->nch++; switch (s->nch) { case 1: UCA0TXBUF = SL(r) << 5 |TL(r)<<4|KL(r)<<3|PL(r)<<2|WL(r)<<1|HL(r); break; case 2: UCA0TXBUF = RL(r)<<6 | AL(r)<<5 | OL(r)<<4 | STAR(r)<<3; break; case 3: UCA0TXBUF = ER(r)<<3 | UR(r)<<2 | FR(r)<<1 | RR(r); break; case 4: UCA0TXBUF = PR(r)<<6 | BR(r)<<5 | LR(r)<<4 | GR(r)<<3 | TR(r)<<2 | SR(r)<<1 | DRS(r); break; case 5: UCA0TXBUF = POUND(r)<<1 | ZRS(r); break; default: s->lc++; if (s->lc != s->nc-1) { s->nch = 0; UCA0TXBUF = 1 << 7; // first packet, no fn or '#' } else { s->flags &= ~CSEND; } } } }
//left right situation static TLDNode *LR(TLDNode *node){ TLDNode *temp; temp=node->left; //perform rotation node->left=RR(temp); return LR(node); }
static int pd_wait_for( int unit, int w, char * msg ) /* polled wait */ { int k, r, e; k=0; while(k < PD_SPIN) { r = RR(1,6); k++; if (((r & w) == w) && !(r & STAT_BUSY)) break; udelay(PD_SPIN_DEL); } e = (RR(0,1)<<8) + RR(0,7); if (k >= PD_SPIN) e |= ERR_TMO; if ((e & (STAT_ERR|ERR_TMO)) && (msg != NULL)) pd_print_error(unit,msg,e); return e; }
/** print one line with udb RR */ static void print_udb_rr(uint8_t* name, udb_ptr* urr) { buffer_type buffer; region_type* region = region_create(xalloc, free); region_type* tmpregion = region_create(xalloc, free); buffer_type* tmpbuffer = buffer_create(region, MAX_RDLENGTH); rr_type rr; ssize_t c; domain_table_type* owners; owners = domain_table_create(region); rr.owner = domain_table_insert(owners, dname_make(region, name, 0)); /* to RR */ rr.type = RR(urr)->type; rr.klass = RR(urr)->klass; rr.ttl = RR(urr)->ttl; buffer_create_from(&buffer, RR(urr)->wire, RR(urr)->len); c = rdata_wireformat_to_rdata_atoms(region, owners, RR(urr)->type, RR(urr)->len, &buffer, &rr.rdatas); if(c == -1) { printf("cannot parse wireformat\n"); region_destroy(region); return; } rr.rdata_count = c; print_rr(stdout, NULL, &rr, tmpregion, tmpbuffer); region_destroy(region); region_destroy(tmpregion); }
static Node NodeDelete(Node rootnode , Node delnode){ if (delnode == NULL || rootnode == NULL){ return NULL; } //node in the left if (delnode -> data < rootnode -> data){ rootnode -> left = NodeDelete(rootnode -> left , delnode); //lose balance if (Height(rootnode -> right) == Height(rootnode -> right) + 2){ Node right = rootnode -> right; if (Height(right -> left) > Height(right -> right)){ rootnode = RL(rootnode); }else{ rootnode = RR(rootnode); } } } //node in the right if (delnode -> data > rootnode -> data){ rootnode -> right = NodeDelete(rootnode -> right , delnode); //lose balance if (Height(rootnode -> left) == Height(rootnode -> right) + 2){ Node left = rootnode -> left; if (Height(left -> right) > Height(left -> left)){ rootnode = LR(rootnode); }else{ rootnode = LL(rootnode); } } } //delnode is rootnode if (delnode -> data == rootnode -> data){ if ((rootnode -> left != NULL) && (rootnode -> right != NULL)){ //left is lager than right if (Height(rootnode -> left) > Height(rootnode -> right)){ Node max = FindMax(rootnode -> left); rootnode -> data = max -> data; rootnode -> left = NodeDelete(rootnode -> left , max); }else{ //right is lager than left Node min = FindMin(rootnode -> right); rootnode -> data = min -> data; rootnode -> right = NodeDelete(rootnode -> right , min); } }else{ //left || right in null Node tmp = rootnode; if (rootnode -> left != NULL){ rootnode = rootnode -> left; }else{ rootnode = rootnode -> right; } free(tmp); } } return rootnode; }
void insert(RBT * T,int x) { RNode * y = new RNode; y->val = x; y->L = y->R = y->F = T->nil; _insert(T,T->root,y); y->color = RED; while((y != T->root) && (y->F->color == RED)) { if(y->F == y->F->F->L) { RNode * u = y->F->F->R; if(u->color == RED) { y->F->color = u->color = BLACK; u->F->color = RED; y = u->F; } else { if(y == y->F->R) y=y->F,LR(T,y); // 定义|x|为x的黑高度,则|y->F->L| == |y->F->R| => |y->F->L| = |y->L| =>足够对于y->F左旋 //假设修改,并且|y->F->F->R| == |y->R| 足够使y->F->F右旋 y->F->color = BLACK; y->F->F->color = RED; RR(T,y->F->F); } }else{ RNode * u = y->F->F->L; if(u->color == RED) { y->F->color = u->color = BLACK; u->F->color = RED; y = u->F; }else { if(y == y->F->L) y = y->F,RR(T,y); y->F->color = BLACK; y->F->F->color = RED; LR(T,y->F->F); } } } T->root->color = BLACK; }
/** list rrs */ static void list_rrs(udb_base* udb, udb_ptr* rrset, udb_ptr* domain) { udb_ptr rr; udb_ptr_new(&rr, udb, &RRSET(rrset)->rrs); while(rr.data) { print_udb_rr(DOMAIN(domain)->name, &rr); udb_ptr_set_rptr(&rr, udb, &RR(&rr)->next); } udb_ptr_unlink(&rr, udb); }
/* delete sessid from AVLTree */ AVLTree_Node * deletion(AVLTree_Node *T,uint16_t x) { AVLTree_Node *p; if(T==NULL) { return NULL; } else if(x > T->data) // insert in right subtree { T->right=deletion(T->right,x); if(BF(T)==2) if(BF(T->left)>=0) T=LL(T); else T=LR(T); } else if(x<T->data) { T->left=deletion(T->left,x); if(BF(T)==-2)//Rebalance during windup if(BF(T->right)<=0) T=RR(T); else T=RL(T); } else { //data to be deleted is found if(T->right !=NULL) { //delete its inorder succesor p=T->right; while(p->left != NULL) p=p->left; T->data=p->data; T->head=p->head; T->right=deletion(T->right,p->data); if(BF(T)==2)//Rebalance during windup if(BF(T->left)>=0) T=LL(T); else T=LR(T); } else return(T->left); } T->ht=height(T); return(T); }
inline void Splay(long x, long G) { long F, FF; while ((F = S[x].p) != G) if ((FF = S[F].p) == G) if (x == S[F].l) RR(F); else LL(F); else if (F == S[FF].l) if (x == S[F].l) RR(FF), RR(F); else LL(F), RR(FF); else if (x == S[F].l) RR(F), LL(FF); else LL(FF), LL(F); if (!G) root = x; }
/*************************************************** function: PassProcessesToCPU purpose: Schedule tasks to be processed by CPU according to chosen method. input: current clock time ***************************************************/ void Scheduler::PassProcessesToCPU(int time) { current_time = time; if(p_table.AllTasksComplete()) { if(output_scheduler_info) cout << "No remaining tasks to be processed.\n"; return; } /// Identify running states switch(schedule_method) { case fcfs: FCFS(); break; case rr: RR(); break; case srt: SRT(); break; case hrrn: HRRN(); break; } if(output_scheduler_info == TRUE){ cout << "Clock Time = "<<current_time<<", \tTasks: "; } /// Proces running states for(int i = 0; i < p_table.tasks.size(); i++) if(p_table.tasks[i].state == running) { if(p_table.tasks[i].process.response_time == 0) p_table.tasks[i].process.response_time = current_time - p_table.tasks[i].process.arrival_time; if(output_scheduler_info == TRUE) cout << p_table.tasks[i].process.pid << ",\t"; p_table.tasks[i].process.time_serviced += 1; // Spend 1 clock cycle processing task } if(output_scheduler_info == TRUE) cout << endl; /// Update state of each task UpdateWaitStates(); for(int i = 0; i < p_table.tasks.size(); i++) // Update each running state { if(p_table.tasks[i].state == running) { p_table.tasks[i].UpdateState(); // Must come after 'UpdateWaitStates()' if(p_table.tasks[i].state == complete) p_table.tasks[i].completion_time = current_time+1; // Store time at which task was completed if(current_method == rr){ if(p_table.tasks[i].state == blocked || p_table.tasks[i].state == waiting) p_table.tasks[i].process.blocked_time = current_time+1; } } } }
/** Função recursiva de inserção na árvore AVL. */ int insertAVL_TreeR(struct AVL_TreeNode **node, void *elem, int *h) { if (!*node) {//se o nó não existir, é criado um novo no AVL_TreeNode *novo = (AVL_TreeNode*) malloc(sizeof (AVL_TreeNode)); novo->elem = elem; novo->fb = 0; novo->left = NULL; novo->right = NULL; *node = novo; *h = 1; //haverá mudança na altura return 1; } else { if (*(int*) (*node)->elem == *(int*) elem) { *h = 0; return 0; } if (*(int*) elem < *(int*) (*node)->elem) { insertAVL_TreeR(&((*node)->left), elem, h); if (*h == 1) { //se h = 1 então houve mudança na altura da arvore então terã de recalcular o FB e talvez rebalancear. //Se rebalancear então não haverá mais mudança na altura. if ((*node)->fb == 0) { //Se fb era 0 então estava balanceada, (*node)->fb--; //inserindo alguém a esquerda, diminui o fb de 1 *h = 1; //e haverá mudança na altura } else if ((*node)->fb == 1) {//se o fb era 1 então a direita era mais pesada (*node)->fb--; //Inserindo alguém na esquerda o fb diminuirá de 1 *h = 0; //e não haverá mudança na altura } else if ((*node)->fb == -1) {//se o fb era -1 então a esquerda é mais pesada (*node)->fb = 0; //insserindo alguém na esquerda o fb irá a dois e deverá ser rebalanceada, voltando a 0 RR(&(*node), h); //caso1 } } } else if (*(int*) elem > *(int*) (*node)->elem) { insertAVL_TreeR(&((*node)->right), elem, h); if (*h == 1) { if ((*node)->fb == 1) {//Se fb era 1 então a direita ja tinha alguem, faz uma rotação para esquerda e a altura não muda LR(&(*node), h); *h = 0; } else if ((*node)->fb == 0) { (*node)->fb++; *h = 1; } else if ((*node)->fb == -1) { //Se fb era -1 então a esquerda era maior, como foi inserido na direita, a altura não muda. (*node)->fb++; *h = 0; } } } } }