Пример #1
0
/*
	initialize all processes to "entering work section"
*/
int init()
{
	int p;
	double dtw, dtwsig;

	ncycle = 0;
	global_time = 0;
	lsttime = 0;
	barcnt = 0;
	nwaiting = 0;
	critfree = TRUE;

	dtw = 1. / nproc;	/* mean process work time */
	dtwsig = dtw * alpha;	/* std deviation of work time */
	gaussinit(dtw, dtwsig);

	for (p = 1; p <= nproc; p++) {
		eventtab[p].type = NULLEVENT;
	}

	for (p = 1; p <= nproc; p++) {
		addevent(ENTERWORK, p, global_time);
	}

	return (0);
}
Пример #2
0
/*
	take the action prescribed by 'ev', update the clock, and
	generate any subsequent events
*/
static int doevent(struct event *ev)
{
	double nxttime;
	int i, p, proc;

	global_time = ev->time;
	proc = ev->proc;

	switch (ev->type) {
	case TRYCRIT:
		if (critfree == TRUE)
			addevent(ENTERCRIT, proc, global_time);
		else
			addwaiting(proc);
		break;
	case ENTERCRIT:
		critfree = FALSE;
		nxttime = global_time + dtcrit();
		addevent(LEAVECRIT, proc, nxttime);
		break;
	case LEAVECRIT:
		critfree = TRUE;
		addevent(ATBARRIER, proc, global_time);
		if ((p = getwaiting()) != 0) {
			nxttime = global_time;
			addevent(ENTERCRIT, p, nxttime);
		}
		break;
	case ATBARRIER:
		barcnt++;
		if (barcnt == nproc) {
			nxttime = global_time;
			for (i = 1; i <= nproc; i++) {
				nxttime += dtspinoff();
				addevent(ENTERWORK, i, nxttime);
			}
			barcnt = 0;
			ncycle++;
		}
		break;
	case ENTERWORK:
		nxttime = global_time + dtwork();
		if (ncycle < ncycmax)
			addevent(LEAVEWORK, proc, nxttime);
		break;
	case LEAVEWORK:
		addevent(TRYCRIT, proc, global_time);
		break;
	default:
		tst_brkm(TBROK, NULL, "Illegal event");
		break;
	}
	return (0);
}
Пример #3
0
int     simple_pression (int evtype, int voice, int data)
{
    Event   ev;

    if (istaping)
    {
	ev.dtime = t - lasteventtime;
	lasteventtime = t;
	ev.type = evtype;
	ev.voice = voice;
	ev.val = data;
	addevent (&curEVreg, &ev);
    }
    return 0;			/* JDJDJDJD pas d'API pour ça ? */
}
Пример #4
0
/* JDJDJDJD vaudrait mieux mettre ca au moment exact du changement de pattern, ou pas ?? */
int     pattern_pression (int evtype, int voice, int data)
{
    Event   ev;
    Patbut *pat = gpatbut[voice];

    pat->nncurpattern = (pat->radiobank.value << 3) + pat->radiopattern.value;

    if (istaping)
    {
	ev.dtime = t - lasteventtime;
	lasteventtime = t;
	ev.type = evtype;
	ev.voice = voice;
	ev.val = pat->nncurpattern;
	addevent (&curEVreg, &ev);
    }
    return 0;			/* JDJDJDJD pas d'API pour ça ? */
}
Пример #5
0
int     taping_pression (int evtype, int voice, int data)
{
    if (istaping)
    {
#ifdef DEBSEQU
	fprintf (stderr, "entering recording mode\n");
#endif
	t = 0;			/* JDJDJD c'est violent ca */
	if (start_recording ())
	    return -1;
	if (initcurEVplay == NULL)
	    generate_freeze ();
	else
	    start_playing ();
    }
    else
    {
#ifdef DEBSEQU
	fprintf (stderr, "quiting recording mode\n");
#endif
	addevent (&curEVreg, &event_end);
	if (initcurEVplay != NULL)
	{
	    EventBuf *temp = evbuf_fusion (initcurEVplay, initcurEVreg);

	    evbuf_remove (initcurEVplay);
	    evbuf_remove (initcurEVreg);
	    initcurEVplay = temp;
	    initcurEVreg = NULL;
	}
	else
	{
	    initcurEVplay = initcurEVreg;
	    initcurEVreg = NULL;
	}
#ifdef DEBSEQU
	fprintf (stderr, "quiting recording mode...done\n");
#endif
    }
    return 0;
}