bool paxserver::in_view(node_id_t node) const { MASSERT(primary(), "Only query in_view of primary"); return vc_state.view.elt_in(node); }
static arith_t nexpr(enum token n) { if (n == UNOT) return !nexpr(t_lex(*++t_wp)); return primary(n); }
// NB: For each timeout in struct pax_serv_timo, there should // be code here to process the timeout void paxserver::do_timo() { // If we just woke up, chill on initiating vc (routes to which are below) // Because we just sent nops, which should induce vc if we aren't part of the view // XXX hardcoded constant if((net->now() - unpaused_tick) < 15) { return; } switch(vc_state.mode) { case vc_state_t::ACTIVE: { std::set<node_id_t> servers = get_other_servers(vc_state.view); if(primary()) { // First check if we have heard from someone not in our view with // a packet sent "recently" (i.e., around half of heartbeat_timo). // If so, view change. for(auto rr_it = recent_recv.begin(); rr_it != recent_recv.end(); ++rr_it) { if(servers.count(rr_it->first) == 0 // XXX hardcoded constant && (net->now() - rr_it->second) < 40) { // Recently received a message from an out of view host, vc LOG(l::DBG_EV, id_str() << " out of view now:" << net->now() << " host: " << rr_it->first << " gotit:" << rr_it->second << "\n"); rr_it->second = 0; initiate_vc(true); return; } } // Now check to see we have heard from everyone in view for(const auto& serv : servers) { if(net->timop(recent_recv[serv], ps_timo.dead_timo)) { LOG(l::DBG_EV, id_str() << " active timeout now:" << net->now() << " recent recv: " << recent_recv[serv] << " nid:" << serv << "\n"); initiate_vc(true); return; } } } else { // Everyone else checks primary if(net->timop(recent_recv[vc_state.view.primary], ps_timo.dead_timo)) { // If we haven't heard from the manager, initiate_vc LOG(l::DBG_EV, id_str() << " non-primary timeout now:" << net->now() << " recent recv: " << recent_recv[vc_state.view.primary] << " pr: " << vc_state.view.primary << "\n"); initiate_vc(true); return; } } } break; case vc_state_t::MANAGER: { // If we haven't announced new view, & it is possible // see if we have waited long enough if(vc_mgr.announce_nv == false && vc_mgr.view_possible && net->timop(vc_mgr.view_possible, ps_timo.vca_timo)) { LOG(l::DBG_EV, id_str() << " manager vc complete timeout now:" << net->now() << "\n"); form_newview(); announce_newview(); vc_mgr.announce_nv = true; } MASSERT(ps_timo.vca_timo < ps_timo.dead_timo, "Should wait longer for dead node than to complete a vc"); // Now see if we haven't heard from anyone in too long a time. std::set<node_id_t> servers = net->get_serv_ids(nid); tick_t most_recent_recv = (tick_t)0; node_id_t recent_nid = 0; for(const auto& serv : servers) { if(recent_recv[serv] > most_recent_recv) { most_recent_recv = recent_recv[serv]; recent_nid = serv; } } if(net->timop(most_recent_recv, ps_timo.dead_timo)) { LOG(l::DBG_EV, id_str() << " manager timeout now:" << net->now() << " most recent: " << most_recent_recv << " nid:" << recent_nid << "\n"); initiate_vc(true); return; } } break; case vc_state_t::UNDERLING: { if(net->timop(recent_recv[vc_state.proposed_vid.manager], ps_timo.dead_timo)) { // If we don't hear from the manager, initiate_vc LOG(l::DBG_EV, id_str() << " underling timeout now:" << net->now() << " recent_recv: " << recent_recv[vc_state.proposed_vid.manager] << " nid:" << vc_state.proposed_vid.manager << "\n"); initiate_vc(true); } } break; default: MASSERT(0, "Yikes"); } }
void panlcmd( union both_scr *posptr, int *line_no, int *col_no, unsigned int *panel, int *nfield, int **rowcol, char inptext[] [25] [80], char dsn[56], int maxlrecl, unsigned int cmd[], int *coloffset, struct bufline **first, struct bufline **curr, int wherest[25], int wherend[25], int *dschanged, struct lineptrs *place, int rightmar) /**********************************************************************/ /* */ /* Execute panel commands. */ /* */ /**********************************************************************/ /* */ /* This is ZEDIT source material. */ /* */ /* ZEDIT Source Materials are intellectual property */ /* (c) Copyright 1987,2001 by Clyde Thomas Zuber. */ /* */ /**********************************************************************/ { FILE *ds; unsigned int pcmd; char selfor[8]; /* cmd subscript */ register int c; /* turn off cmd grouping */ pcmd = cmd[0] & WHCHPAN; if (pcmd & PRIMARY) { *panel = PRIMARY; primary(posptr, line_no, col_no, nfield, rowcol, inptext); } /* end then */ else if (pcmd & DSENTRY) { *panel = DSENTRY; switch(cmd[3]) { case SEL_BROWPAN: strcpy(selfor, "BROWSE"); break; case SEL_EDITPAN: strcpy(selfor, "EDIT"); break; case SEL_COPYDSN: strcpy(selfor, "COPY"); break; case IGRKPRC: strcpy(selfor, "IMPGRK"); break; case IHEBPRC: strcpy(selfor, "IMPHEB"); break; case EGRKPRC: strcpy(selfor, "EXPGRK"); break; case EHEBPRC: strcpy(selfor, "EXPHEB"); break; case EHHIPRC: strcpy(selfor, "EXPHHI"); break; } /* end switch */ dsentry(posptr, line_no, col_no, nfield, rowcol, inptext, selfor); } /* end then */ else if (pcmd & BROWPAN) { ds = fopen(dsn, OLD_INPUT); if (ds) { *first = readbuf(posptr, ds, maxlrecl); *curr = *first; fclose(ds); *panel = BROWPAN; browpan(posptr, line_no, col_no, nfield, rowcol, inptext, dsn, rightmar); *coloffset = 0; buftscr(posptr, *nfield, (int (*)[5]) *rowcol, inptext, *curr, maxlrecl, *coloffset, wherest, wherend, place, YES); } /* end then */ else { /* clean off the stack */ for (c = 2; c < STACKMAX; ++c) cmd[c] = NOP; cmd[1] = BROWSE; dispmsg(posptr, PANLCMD_MSG1); } /* end else */ } /* end then */ else if (pcmd & EDITPAN) { ds = fopen(dsn, MOD_INOUT); #ifdef S370 if (ds) ds = fopen(dsn, OLD_INPUT); #endif if (ds) { *dschanged = NO; fseek(ds, 0L, SEEK_SET); *first = readbuf(posptr, ds, maxlrecl); *curr = *first; fclose(ds); *panel = EDITPAN; editpan(posptr, line_no, col_no, nfield, rowcol, inptext, dsn, rightmar); *coloffset = 0; buftscr(posptr, *nfield, (int (*)[5]) *rowcol, inptext, *curr, maxlrecl, *coloffset, wherest, wherend, place, NO); } /* end then */ else { /* clean off the stack */ for (c = 2; c < STACKMAX; ++c) cmd[c] = NOP; cmd[1] = EDIT; dispmsg(posptr, PANLCMD_MSG2); } /* end else */ } /* end then */ else if (pcmd & CFGKPAN) { *panel = CFGKPAN; cfgkpan(posptr, line_no, col_no, nfield, rowcol, inptext); } /* end then */ else if (pcmd & CFGFPAN) { *panel = CFGFPAN; cfgfpan(posptr, line_no, col_no, nfield, rowcol, inptext); } /* end then */ } /* end panlcmd */
Node *regexp(void) /* top-level parse of reg expr */ { return (alt(concat(primary()))); }
double primary() // deal with numbers, square roots, exponents, parentheses, and brackets { Token t = ts.get(); switch (t.kind) { case root: { t = ts.get(); if (t.kind != '(') error("'(' expected"); double d = expression(); if (d < 0) error ("negative argument for sqrt()"); t = ts.get(); if (t.kind != ')') error ("')' expected"); return sqrt(d); } case exponent: { t = ts.get(); if (t.kind != '(') error("'(' expected"); double d = expression(); t = ts.get(); if (t.kind != ',') error("expected two arguments for pow()"); int exp = narrow_cast<int>(expression()); t = ts.get(); if (t.kind != ')') error("')'expected"); return power(d, exp); } case '{': // handle '{' expression '}' { double d = expression(); t = ts.get(); if (t.kind != '}') error("'}' expected"); return d; } case '(': // handle '(' expression ')' { double d = expression(); t = ts.get(); if (t.kind != ')') error("')' expected"); return d; } case number: // we use '8' to represent a number return t.value; // return the number's value case name: return symtable.get(t.name); case '-': return -primary(); case '+': return primary(); default: error("primary expected"); } }
struct conditionNode* condition() { struct conditionNode* cNode; struct varNode* op1; struct varNode* op2; struct statementNode* tBranch; struct statementNode* fBranch; int op; cNode = make_condition(); ttype = getToken(); if ((ttype == ID)|(ttype == NUM)) { ungetToken(); //ungetToken since it still be parsed cNode->op1 = primary(); //left operand of a condition is a primary ttype = getToken(); if ((ttype == GREATER)|(ttype == GTEQ)|(ttype == LESS) |(ttype == NOTEQUAL)|(ttype == LTEQ)) { cNode->operator = ttype; //relop is set to >, <, etc. ttype = getToken(); if ((ttype == ID)|(ttype == NUM)) { ungetToken(); //ungetToken since it still be parsed cNode->op2 = primary(); //right operand of a condition is a primary ttype = getToken(); if(ttype == RPAREN) { ttype = getToken(); if(ttype == THEN) { cNode->trueBranch = stmt_list(); return cNode; } else { return NULL; } } else { return NULL; } } else { return NULL; } } else { return NULL; } } else { return NULL; } }
struct assignNode* expr(struct assignNode* assign) { struct varNode* oper1; struct varNode* oper2; int oper; ttype = getToken(); if (ttype == NUM) { printf("NUM: %d\n",ttype); assign->op1 = primary(); ttype = getToken(); if ((ttype == PLUS) | (ttype == MINUS) | (ttype == MULT) | (ttype == DIV)) { assign->oper = ttype; //op is set + - * / assign->op2 = primary(); } ungetToken(); return assign; } else if (ttype == ID) { printf("ID: %d\n",ttype); //oper1 = symSearch(token); /*if(oper1 != NULL) //{ //assign->op1->id = oper1->vID;*/ assign->op1 = primary(); printf("ASSIGN ID %s\n", assign->op1->id); ttype = getToken(); printf("PLUS: %d\n",ttype); if ((ttype == PLUS) | (ttype == MINUS) | (ttype == MULT) | (ttype == DIV)) { assign->oper = ttype; ttype = getToken(); if(ttype == ID) { printf("ID: %d\n",ttype); /*oper2 = symSearch(token); //printf("oper2: %s\n",oper2->vID); //if(oper2 != NULL) //{ //assign->op2 = oper2; //assign->op2->id = oper1->vID; */ /*ttype = getToken(); printf("SEMICOLON: %d\n",ttype); if(ttype == SEMICOLON) { //ungetToken(); */ assign->op2 = primary(); return assign; /*} else { return NULL; } */ /*} //else //{ // return NULL; //} */ } else { ungetToken(); } } else { return NULL; } //} } }
/* binary operator expression */ Expr * binaryExpr(int op, Expr *arg1, Expr *arg2) { Expr *x; Expr *arg = arg1; int sts = 0; /* error guard */ if (arg1 == NULL) return NULL; if (arg1 != NULL && arg2 != NULL) { if (op != CND_MATCH && op != CND_NOMATCH) { /* check domains */ sts = checkDoms(arg1, arg2); /* decide primary argument for inheritance of Expr attributes */ arg = primary(arg1, arg2); } else { regex_t *pat; pat = alloc(sizeof(*pat)); if (regcomp(pat, (char *)arg2->ring, REG_EXTENDED|REG_NOSUB) != 0) { /* bad pattern */ fprintf(stderr, "illegal regular expression \"%s\"\n", (char *)arg2->ring); free(pat); return NULL; } #if PCP_DEBUG if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "binaryExpr: regex=\"%s\" handle=" PRINTF_P_PFX "%p\n", (char *)arg2->ring, pat); } #endif /* * change operand from the string form of the pattern to the * compiled regex */ free(arg2->ring); arg2->tspan = 1; arg2->ring = pat; arg2->sem = SEM_REGEX; sts = 1; } } /* construct expression node */ x = newExpr(op, arg1, arg2, arg->hdom, arg->e_idom, arg->tdom, abs(arg->tdom), arg->sem); #if PCP_DEBUG if (sts == 0 && (pmDebug & DBG_TRACE_APPL1)) { fprintf(stderr, "binaryExpr: checkDoms(" PRINTF_P_PFX "%p, " PRINTF_P_PFX "%p) failed ...\n", arg1, arg2); __dumpTree(1, x); } #endif newRingBfr(x); findEval(x); /* evaluate constant expression now */ evalConst(x); return x; }
/* propagate instance domain, semantics and units from argument expressions to parents */ static void instExpr(Expr *x) { int up = 0; Expr *arg1 = x->arg1; Expr *arg2 = x->arg2; Expr *arg = primary(arg1, arg2); /* semantics ... */ if (x->sem == SEM_UNKNOWN) { if (arg2 == NULL) { /* unary expression */ if (arg1->sem != SEM_UNKNOWN) { up = 1; x->sem = arg1->sem; } } else if ((arg1->sem != SEM_UNKNOWN) && (arg2->sem != SEM_UNKNOWN)) { /* binary expression with known args */ up = 1; x->sem = arg->sem; } /* binary expression with unknown arg */ else return; } /* units ... */ if (UNITS_UNKNOWN(x->units)) { if (arg2 == NULL) { /* unary expression */ if (!UNITS_UNKNOWN(arg1->units)) { up = 1; x->units = arg1->units; } if (x->op == CND_INSTANT && x->metrics->desc.sem == PM_SEM_COUNTER) { up = 1; x->units.dimTime++; } if (x->op == CND_RATE) { up = 1; x->units.dimTime--; } } else if (!UNITS_UNKNOWN(arg1->units) && !UNITS_UNKNOWN(arg2->units)) { /* binary expression with known args */ up = 1; x->units = arg->units; if (x->op == CND_MUL) { x->units.dimSpace = arg1->units.dimSpace + arg2->units.dimSpace; x->units.dimTime = arg1->units.dimTime + arg2->units.dimTime; x->units.dimCount = arg1->units.dimCount + arg2->units.dimCount; } else if (x->op == CND_DIV) { x->units.dimSpace = arg1->units.dimSpace - arg2->units.dimSpace; x->units.dimTime = arg1->units.dimTime - arg2->units.dimTime; x->units.dimCount = arg1->units.dimCount - arg2->units.dimCount; } } } /* instance domain */ if ((x->e_idom != -1) && (x->e_idom != arg->e_idom)) { up = 1; x->e_idom = arg->e_idom; x->tspan = (x->e_idom >= 0) ? x->e_idom : abs(x->hdom); x->nvals = x->tspan * x->nsmpls; x->valid = 0; newRingBfr(x); } if (up && x->parent) instExpr(x->parent); }