Beispiel #1
0
static Symbol *
do_same(Lextok *n, Symbol *v, int xinit)
{	Lextok *tmp, *fp, *tl;
	int ix = eval(n->lft);
	int oln = lineno;
	Symbol *ofn = Fname;

	lineno = n->ln;
	Fname = n->fn;
	
	/* n->sym->type == STRUCT
	 * index:		n->lft
	 * subfields:		n->rgt
	 * structure template:	n->sym->Slst
	 * runtime values:	n->sym->Sval
	 */
	if (xinit) ini_struct(v);	/* once, at top level */

	if (ix >= v->nel || ix < 0)
	{	printf("spin: indexing %s[%d] - size is %d\n",
				v->name, ix, v->nel);
		fatal("indexing error \'%s\'", v->name);
	}
	if (!n->rgt || !n->rgt->lft)
	{	non_fatal("no subfields %s", v->name);	/* i.e., wants all */
		lineno = oln; Fname = ofn;
		return ZS;
	}

	if (n->rgt->ntyp != '.')
	{	printf("bad subfield type %d\n", n->rgt->ntyp);
		alldone(1);
	}

	tmp = n->rgt->lft;
	if (tmp->ntyp != NAME && tmp->ntyp != TYPE)
	{	printf("bad subfield entry %d\n", tmp->ntyp);
		alldone(1);
	}
	for (fp = v->Sval[ix]; fp; fp = fp->rgt)
	for (tl = fp->lft; tl; tl = tl->rgt)
		if (!strcmp(tl->sym->name, tmp->sym->name))
		{	lineno = oln; Fname = ofn;
			return tl->sym;
		}
	fatal("cannot locate subfield %s", tmp->sym->name);
	return ZS;
}
Beispiel #2
0
/*
 * Decrement the loads_pending counter; when counter reaches
 * zero, call the loaddone callback that was initially set by
 * dns_zt_asyncload().
 */
static isc_result_t
doneloading(dns_zt_t *zt, dns_zone_t *zone, isc_task_t *task) {
	isc_boolean_t destroy = ISC_FALSE;
	dns_zt_allloaded_t alldone = NULL;
	void *arg = NULL;

	UNUSED(zone);
	UNUSED(task);

	REQUIRE(VALID_ZT(zt));

	RWLOCK(&zt->rwlock, isc_rwlocktype_write);
	INSIST(zt->loads_pending != 0);
	INSIST(zt->references != 0);
	zt->references--;
	if (zt->references == 0)
		destroy = ISC_TRUE;
	zt->loads_pending--;
	if (zt->loads_pending == 0) {
		alldone = zt->loaddone;
		arg = zt->loaddone_arg;
		zt->loaddone = NULL;
		zt->loaddone_arg = NULL;
	}
	RWUNLOCK(&zt->rwlock, isc_rwlocktype_write);

	if (alldone != NULL)
		alldone(arg);

	if (destroy)
		zt_destroy(zt);

	return (ISC_R_SUCCESS);
}
Beispiel #3
0
void plu(int nbi, int nbj)
{
	int i, j;
	for (i = 0; i < nbi; ++i) {
		for (j = 0; j < nbj; ++j) {
			args[i][j].bi = i;
			args[i][j].bj = j;
			args[i][j].nbi = nbi;
			args[i][j].nbj = nbj;
		}
	}
#define USE_FORK 1
#define RBOUNDS(__x) (0 <= (__x) && (__x) < nbi)
#define CBOUNDS(__x) (0 <= (__x) && (__x) < nbj)
#define READY(_x, _y) ( \
		(!RBOUNDS((_x)-1) || DONE == status[(_x)-1][(_y)]) && \
		(!CBOUNDS((_y)-1) || DONE == status[(_x)][(_y)-1]))
	memset(status, 0, sizeof(status));
	while (!alldone(nbi, nbj)) {
		for (i = 0; i < nbi; ++i) {
			for (j = 0; j < nbj; ++j) {
				if (!READY(i, j) || DONE == status[i][j])
					continue;
				status[i][j] = RUNNING;
#if USE_FORK
				pthread_create(&threads[nbj * i + j], NULL, lu, &args[i][j]);
#endif
			}
		}
		for (i = 0; i < nbi; ++i) {
			for (j = 0; j < nbj; ++j) {
				if (RUNNING != status[i][j])
					continue;
#if USE_FORK
				pthread_join(threads[nbj * i + j], NULL);
#endif
				status[i][j] = DONE;
			}
		}
	}
	/* Clear bottom of A (which is now U) and make L's diagonals 1s. */
	for (i = 0; i < n; ++i) {
		for (j = 0; j < n; ++j) {
			if (i > j)
				VAL(A,i,j) = 0;
			if(i == j)
				VAL(L,i,i) = 1;
		}
	}
}
int main(int argc, char **argv) { 
    
    long i,errors=0,help=0; 
 
    signal(SIGINT, endit); 
    
    log_port=LOG_ALWAYS; 
    for (i=1; i<argc; i++) { 
	if (strcmp(argv[i],"-help")==0) { 
	    help++;
	} else if (strcmp(argv[i],"-all")==0) { 
	    log_port |= LOG_LOAD|LOG_BLOCK|LOG_PAGE|LOG_BRANCH; 
	} else if (strcmp(argv[i],"-load")==0) { 
	    log_port |= LOG_LOAD; 
	} else if (strcmp(argv[i],"-block")==0) { 
	    log_port |= LOG_BLOCK; 
	} else if (strcmp(argv[i],"-page")==0) { 
	    log_port |= LOG_PAGE; 
	} else if (strcmp(argv[i],"-branch")==0) { 
	    log_port |= LOG_BRANCH; 
	} else if (strcmp(argv[i],"-dead")==0) { 
	    log_port |= LOG_DEAD; 
	} else if (strcmp(argv[i],"-seed")==0) { 
	    if (sscanf(argv[++i],"%ld",&seed)!=1) {
		fprintf(stderr,
			"%s: could not read random seed from command line\n",
			argv[0]); 
		errors++; 
	    } else if (seed<1 || seed>((1<<30)-1)) {
		fprintf(stderr,
			"%s: random seed must be between 1 and %d\n",
			argv[0], (1<<30)-1); 
		errors++; 
	    } 
	} else if (strcmp(argv[i],"-csv")==0) { 
	    output = fopen("output.csv", "w"); 
            if (!output) { 
		fprintf(stderr,
			"%s: could not open output.csv for writing\n",
			argv[0]); 
		errors++; 
	    } 
	    pages = fopen("pages.csv", "w"); 
            if (!pages) { 
		fprintf(stderr,
			"%s: could not open pages.csv for writing\n",
			argv[0]); 
		errors++; 
	    } 
	} else if (strcmp(argv[i],"-procs")==0) { 
	    if (sscanf(argv[++i],"%ld",&procs)!=1) {
		fprintf(stderr,
			"%s: could not read number of processors from command line\n",
			argv[0]); 
		errors++; 
	    } else if (procs<1 || procs>MAXPROCESSES) {
		fprintf(stderr,
			"%s: number of processors must be between 1 and %d\n",
			argv[0], MAXPROCESSES); 
		errors++; 
	    } 
        } else { 
	    fprintf(stderr, "t4: unrecognized argument %s\n", argv[i]); 
	    errors++; 
 	} 
    } 
    if (errors || help) { 
	fprintf(stderr, "%s usage: %s \n", argv[0], argv[0]); 
        fprintf(stderr, "  -all       log everything\n"); 
	fprintf(stderr, "  -load      log loading of processes\n"); 
	fprintf(stderr, "  -unload    log unloading of processes\n"); 
	fprintf(stderr, "  -branch    log program branches\n"); 
	fprintf(stderr, "  -page      log page in and out\n"); 
	fprintf(stderr, "  -seed 512  set random seed to 512\n"); 
	fprintf(stderr, "  -procs 4   run only four processors\n"); 
	fprintf(stderr, "  -dead      detect deadlocks\n"); 
	fprintf(stderr, "  -csv       generate output.csv and pages.csv for graphing\n");
	if(errors) {
	    return EXIT_FAILURE;
	}
	else {
	    return EXIT_SUCCESS;
	}
    } 
    if (seed==0) { 
	seed = (time(NULL)*38491+71831+time(NULL)*time(NULL))&((1<<30)-1); 
    } 
    srand48(seed); 
    sim_log(LOG_ALWAYS,"random seed %d\n", seed); 
    sim_log(LOG_ALWAYS,"using %d processors\n", procs); 
    
    allinit(); 
    while (!alldone()) { // all processes inactive
	allstep(); 	 // advance time one tick; if process done, reload
        allage(); 	 // advance time for page wait variables. 
        callyou(); 	 // call your program
	sysclock++;      // remember new time. 
	allblocked();    // deadlock detection 
    } 
    allscore(); 

    return EXIT_SUCCESS;

} 
Beispiel #5
0
void
match_trail(void)
{	int i, a, nst;
	Element *dothis;
	char snap[512], *q;

	/*
	 * if source model name is leader.pml
	 * look for the trail file under these names:
	 *	leader.pml.trail
	 *	leader.pml.tra
	 *	leader.trail
	 *	leader.tra
	 */

	if (ntrail)
		sprintf(snap, "%s%d.trail", oFname->name, ntrail);
	else
		sprintf(snap, "%s.trail", oFname->name);

	if ((fd = fopen(snap, "r")) == NULL)
	{	snap[strlen(snap)-2] = '\0';	/* .tra */
		if ((fd = fopen(snap, "r")) == NULL)
		{	if ((q = strchr(oFname->name, '.')) != NULL)
			{	*q = '\0';
				if (ntrail)
					sprintf(snap, "%s%d.trail",
						oFname->name, ntrail);
				else
					sprintf(snap, "%s.trail",
						oFname->name);
				*q = '.';

				if ((fd = fopen(snap, "r")) != NULL)
					goto okay;

				snap[strlen(snap)-2] = '\0';	/* last try */
				if ((fd = fopen(snap, "r")) != NULL)
					goto okay;
			}
			printf("spin: cannot find trail file\n");
			alldone(1);
	}	}
okay:		
	if (xspin == 0 && newer(oFname->name, snap))
	printf("spin: warning, \"%s\" is newer than %s\n",
		oFname->name, snap);

	Tval = 1;

	/*
	 * sets Tval because timeouts may be part of trail
	 * this used to also set m_loss to 1, but that is
	 * better handled with the runtime -m flag
	 */

	hookup();

	while (fscanf(fd, "%d:%d:%d\n", &depth, &pno, &nst) == 3)
	{	if (depth == -2) { start_claim(pno); continue; }
		if (depth == -4) { merger = 1; ana_src(0, 1); continue; }
		if (depth == -1)
		{	if (verbose)
			{	if (columns == 2)
				dotag(stdout, " CYCLE>\n");
				else
				dotag(stdout, "<<<<<START OF CYCLE>>>>>\n");
			}
			continue;
		}

		if (cutoff > 0 && depth >= cutoff)
		{	printf("-------------\n");
			printf("depth-limit (-u%d steps) reached\n", cutoff);
			break;
		}

		if (Skip_claim && pno == 0) continue;

		for (dothis = Al_El; dothis; dothis = dothis->Nxt)
		{	if (dothis->Seqno == nst)
				break;
		}
		if (!dothis)
		{	printf("%3d: proc %d, no matching stmnt %d\n",
				depth, pno - Have_claim, nst);
			lost_trail();
		}

		i = nproc - nstop + Skip_claim;

		if (dothis->n->ntyp == '@')
		{	if (pno == i-1)
			{	run = run->nxt;
				nstop++;
				if (verbose&4)
				{	if (columns == 2)
					{	dotag(stdout, "<end>\n");
						continue;
					}
					if (Have_claim && pno == 0)
					printf("%3d: claim terminates\n",
						depth);
					else
					printf("%3d: proc %d terminates\n",
						depth, pno - Have_claim);
				}
				continue;
			}
			if (pno <= 1) continue;	/* init dies before never */
			printf("%3d: stop error, ", depth);
			printf("proc %d (i=%d) trans %d, %c\n",
				pno - Have_claim, i, nst, dothis->n->ntyp);
			lost_trail();
		}
		for (X = run; X; X = X->nxt)
		{	if (--i == pno)
				break;
		}
		if (!X)
		{	printf("%3d: no process %d ", depth, pno - Have_claim);
			printf("(state %d)\n", nst);
			lost_trail();
		}
		X->pc  = dothis;
		lineno = dothis->n->ln;
		Fname  = dothis->n->fn;

		if (dothis->n->ntyp == D_STEP)
		{	Element *g, *og = dothis;
			do {
				g = eval_sub(og);
				if (g && depth >= jumpsteps
				&& ((verbose&32) || ((verbose&4) && not_claim())))
				{	if (columns != 2)
					{	p_talk(og, 1);
		
						if (og->n->ntyp == D_STEP)
						og = og->n->sl->this->frst;
		
						printf("\t[");
						comment(stdout, og->n, 0);
						printf("]\n");
					}
					if (verbose&1) dumpglobals();
					if (verbose&2) dumplocal(X);
					if (xspin) printf("\n");
				}
				og = g;
			} while (g && g != dothis->nxt);
			if (X != NULL)
			{	X->pc = g?huntele(g, 0, -1):g;
			}
		} else
Beispiel #6
0
  TEST(Routing, callbacks)
  {
    zmq::context_t context(1);
    zmq::socket_t alphaSocket(context, ZMQ_PAIR);
    zmq::socket_t betaSocket(context, ZMQ_PAIR);
    std::unique_ptr<zmq::socket_t> alphaSocketRouter(new zmq::socket_t(context, ZMQ_PAIR));
    std::unique_ptr<zmq::socket_t> betaSocketRouter(new zmq::socket_t(context, ZMQ_PAIR));
    alphaSocket.bind("tcp://*:5555");
    betaSocket.bind("tcp://*:5556");
    alphaSocketRouter->connect("tcp://localhost:5555");
    betaSocketRouter->connect("tcp://localhost:5556");

    SocketRouter router;

    router.add_socket(SocketID::ALPHA, alphaSocketRouter);
    router.add_socket(SocketID::BETA, betaSocketRouter);

    Message hello(HELLO);
    Message heartbeat(HEARTBEAT);
    Message problemspec(PROBLEMSPEC);
    Message jobrequest(JOBREQUEST);
    Message job(JOB);
    Message jobswap(JOBSWAP);
    Message alldone(ALLDONE);
    Message goodbye(GOODBYE);

    auto fwdToBeta = [&] (const Message&m)
    { router.send(SocketID::BETA, m);};
    // Bind functionality to the router
    router(SocketID::ALPHA).onRcvHELLO.connect(fwdToBeta);
    router(SocketID::ALPHA).onRcvHEARTBEAT.connect(fwdToBeta);
    router(SocketID::ALPHA).onRcvPROBLEMSPEC.connect(fwdToBeta);
    router(SocketID::ALPHA).onRcvJOBREQUEST.connect(fwdToBeta);
    router(SocketID::ALPHA).onRcvJOB.connect(fwdToBeta);
    router(SocketID::ALPHA).onRcvJOBSWAP.connect(fwdToBeta);
    router(SocketID::ALPHA).onRcvALLDONE.connect(fwdToBeta);
    router(SocketID::ALPHA).onRcvGOODBYE.connect(fwdToBeta);

    router.start(10);//ms per poll
    send(alphaSocket, hello);
    Message rhello = receive(betaSocket);
    send(alphaSocket, heartbeat);
    Message rheartbeat = receive(betaSocket);
    send(alphaSocket, problemspec);
    Message rproblemspec = receive(betaSocket);
    send(alphaSocket, jobrequest);
    Message rjobrequest = receive(betaSocket);
    send(alphaSocket, job);
    Message rjob = receive(betaSocket);
    send(alphaSocket, jobswap);
    Message rjobswap = receive(betaSocket);
    send(alphaSocket, alldone);
    Message ralldone = receive(betaSocket);
    send(alphaSocket, goodbye);
    Message rgoodbye = receive(betaSocket);

    router.stop();
    ASSERT_EQ(hello, rhello);
    ASSERT_EQ(heartbeat, rheartbeat);
    ASSERT_EQ(problemspec, rproblemspec);
    ASSERT_EQ(jobrequest, rjobrequest);
    ASSERT_EQ(job, rjob);
    ASSERT_EQ(jobswap, rjobswap);
    ASSERT_EQ(alldone, ralldone);
    ASSERT_EQ(goodbye, rgoodbye);
  }
void
undostmnt(Lextok *now, int m)
{	Lextok *v;
	int i, j;

	if (!now)
	{	fprintf(tb, "0");
		return;
	}
	lineno = now->ln;
	Fname  = now->fn;
	switch (now->ntyp) {
	case CONST:	case '!':	case UMIN:
	case '~':	case '/':	case '*':
	case '-':	case '+':	case '%':
	case LT:	case GT:	case '&':
	case '|':	case LE:	case GE:
	case NE:	case EQ:	case OR:
	case AND:	case LSHIFT:	case RSHIFT:
	case TIMEOUT:	case LEN:	case NAME:
	case FULL:	case EMPTY:	case 'R':
	case NFULL:	case NEMPTY:	case ENABLED:
	case '?':	case PC_VAL:	case '^':
	case C_EXPR:	case GET_P:
	case NONPROGRESS:
		putstmnt(tb, now, m);
		break;

	case RUN:
		fprintf(tb, "delproc(0, now._nr_pr-1)");
		break;

	case 's':
		if (Pid == eventmapnr) break;

		if (m_loss)
			fprintf(tb, "if (_m == 2) ");
		putname(tb, "_m = unsend(", now->lft, m, ")");
		break;

	case 'r':
		if (Pid == eventmapnr) break;

		for (v = now->rgt, i=j=0; v; v = v->rgt, i++)
			if (v->lft->ntyp != CONST
			&&  v->lft->ntyp != EVAL)
				j++;
		if (j == 0 && now->val >= 2)
			break;	/* poll without side-effect */

		{	int ii = 0, jj;

			for (v = now->rgt; v; v = v->rgt)
				if ((v->lft->ntyp != CONST
				&&   v->lft->ntyp != EVAL))
					ii++;	/* nr of things bupped */
			if (now->val == 1)
			{	ii++;
				jj = multi_oval - ii - 1;
				fprintf(tb, "XX = trpt->bup.oval");
				if (multi_oval > 0)
				{	fprintf(tb, "s[%d]", jj);
					jj++;
				}
				fprintf(tb, ";\n\t\t");
			} else
			{	fprintf(tb, "XX = 1;\n\t\t");
				jj = multi_oval - ii - 1;
			}

			if (now->val < 2)	/* not for channel poll */
			for (v = now->rgt, i = 0; v; v = v->rgt, i++)
			{	switch(v->lft->ntyp) {
				case CONST:
				case EVAL:
					fprintf(tb, "unrecv");
					putname(tb, "(", now->lft, m, ", XX-1, ");
					fprintf(tb, "%d, ", i);
					if (v->lft->ntyp == EVAL)
						undostmnt(v->lft->lft, m);
					else
						undostmnt(v->lft, m);
					fprintf(tb, ", %d);\n\t\t", (i==0)?1:0);
					break;
				default:
					fprintf(tb, "unrecv");
					putname(tb, "(", now->lft, m, ", XX-1, ");
					fprintf(tb, "%d, ", i);
					if (v->lft->sym
					&& !strcmp(v->lft->sym->name, "_"))
					{	fprintf(tb, "trpt->bup.oval");
						if (multi_oval > 0)
							fprintf(tb, "s[%d]", jj);
					} else
						putstmnt(tb, v->lft, m);

					fprintf(tb, ", %d);\n\t\t", (i==0)?1:0);
					if (multi_oval > 0)
						jj++;
					break;
			}	}
			jj = multi_oval - ii - 1;

			if (now->val == 1 && multi_oval > 0)
				jj++;	/* new 3.4.0 */

			for (v = now->rgt, i = 0; v; v = v->rgt, i++)
			{	switch(v->lft->ntyp) {
				case CONST:
				case EVAL:
					break;
				default:
					if (!v->lft->sym
					||  strcmp(v->lft->sym->name, "_") != 0)
					{	nocast=1; putstmnt(tb,v->lft,m);
						nocast=0; fprintf(tb, " = trpt->bup.oval");
						if (multi_oval > 0)
							fprintf(tb, "s[%d]", jj);
						fprintf(tb, ";\n\t\t");
					}
					if (multi_oval > 0)
						jj++;
					break;
			}	}
			multi_oval -= ii;
		}
		break;

	case '@':
		fprintf(tb, "p_restor(II);\n\t\t");
		break;

	case SET_P:
		fprintf(tb, "((P0 *)pptr((trpt->o_priority >> 8)))");
		fprintf(tb, "->_priority = trpt->o_priority & 255");
		break;

	case ASGN:
		if (check_track(now) == STRUCT) { break; }

		nocast=1; putstmnt(tb,now->lft,m);
		nocast=0; fprintf(tb, " = trpt->bup.oval");
		if (multi_oval > 0)
		{	multi_oval--;
			fprintf(tb, "s[%d]", multi_oval-1);
		}
		check_proc(now->rgt, m);
		break;

	case 'c':
		check_proc(now->lft, m);
		break;

	case '.':
	case GOTO:
	case ELSE:
	case BREAK:
		break;

	case C_CODE:
		fprintf(tb, "sv_restor();\n");
		break;

	case ASSERT:
	case PRINT:
		check_proc(now, m);
		break;
	case PRINTM:
		break;

	default:
		printf("spin: bad node type %d (.b)\n", now->ntyp);
		alldone(1);
	}
}