コード例 #1
0
ファイル: critpath.c プロジェクト: ivan-gimenez/timewarp
FUNCTION calculateCritPath()
{
	Ocb * o, *critOcb;
	State *s, *nxtState;
	truncState * lastState;
	Byte duplicateEpt;

	if ( tw_node_num == CRITPATHMASTER )
	{
		_pprintf("Calculating critical path\n");
	}

	duplicateEpt = 0;

	/* Look through each object to find the local object with the state with
		the highest ept. */

	for ( o = fstocb_macro; o != NULLOCB; o = nxtocb_macro ( o ) )
	{

		/* Ignore the stdout object. */

		if ( o->runstat == ITS_STDOUT )
			continue;


		/* Truncate any states still in the state queue.  They're only
			needed for critical path purposes, at this point, and having
			all the states in one queue simplifies matters. */


		for ( s = fststate_macro ( o ) ; s != NULLSTATE; s = nxtState )
		{
			nxtState = nxtstate_macro ( s );

			truncateState ( s );

		}

		lastState = l_prev_macro ( o->tsqh );
		
		/* We expect all objects to have at least one state. */

		if ( l_ishead_macro ( lastState ))
		{
			_pprintf("ocb %s has no state in truncated state queue\n", o->name );
			tester();
		}


		/* Now check to see if this state's Ept is the highest seen so far.
			If so, change both highEpt and critOcb.  In any case, watch for
			duplicates of the highest Ept using duplicateEpt. */

		if ( lastState->Ept > highEpt )
		{	
			highEpt = lastState->Ept; 
			critOcb = o;
			duplicateEpt = 0;
		}
		else
		if ( lastState->Ept < highEpt )
			duplicateEpt = 0;
		else
			duplicateEpt++ ;
	}

	/* We're not prepared to deal with duplicate Epts yet. */

	if ( duplicateEpt )
	{
		_pprintf("duplicate final EPT's = %d\n", highEpt );
		tester();
	}
		
	if ( tw_node_num == CRITPATHMASTER )
	{
		/* If this node is the master, check its contribution immediately. */

		/* highEpt keeps the recently calculated contribution for this node.
			highestEpt, used only on the CRITPATHMASTER node, keeps the
			globally highest Ept for all nodes that have reported, so far. */

		if ( highestEpt < highEpt )
		{
			highestEpt = highEpt;
			strcpy ( critObject, critOcb->name );
			critNode = CRITPATHMASTER;
		}
		else
		if ( highestEpt == highEpt )
		{
			_pprintf("duplicate high Epts %d and %d\n", highestEpt, highEpt);
			tester();
		}	

		nodesReporting--;

		/* The master was the last node to report (or is the only node). 
			Call startCritPath().  (A function is used here because the
			same code in startCritPath() will also be used by checkCritPath().
			So both routines call the function startCritPath(), rather than
			duplicate the code.) */

		if ( nodesReporting == 0 )
		{
			startCritPath ();
		}
	}
	else
	{

		/* This is not the master node.  Send the CP contribution to the
			master node. */

		Msgh * p;
		Critmsg * q;

		p = sysbuf (); 
		q = ( Critmsg *) (p + 1);

		sprintf ( p->snder, "CRIT%d", tw_node_num );
		sprintf ( p->rcver, "CRIT%d", CRITPATHMASTER );
		q->Ept = highEpt;
		q->node = tw_node_num;
		sprintf ( q->object, critOcb->name );

		sysmsg ( CRITMSG, p, sizeof (Critmsg), CRITPATHMASTER );
	}
}
コード例 #2
0
ファイル: screen.c プロジェクト: italia389/MightEMacs
// Build and pop up a buffer containing a list of all screens and their associated buffers.  Render buffer and return status.
int showScreens(Value *rp,int n) {
	Buffer *slistp;
	EScreen *scrp;			// Pointer to current screen to list.
	EWindow *winp;			// Pointer into current screens window list.
	uint wnum;
	StrList rpt;
	int windcol = 7;
	int filecol = 37;
	char *strp,wkbuf[filecol + 16];

	// Get a buffer and open a string list.
	if(sysbuf(text160,&slistp) != SUCCESS)
			// "Screens"
		return rc.status;
	if(vopen(&rpt,NULL,false) != 0)
		return vrcset();

	// Construct the header lines.
	if(vputs(text89,&rpt) != 0 || vputc('\n',&rpt) != 0 ||
	    // "Screen Window      Buffer                File"
	 vputs("------ ------  --------------------  -------------------------------",&rpt) != 0)
		return vrcset();

	// For all screens...
	scrp = sheadp;
	do {
		// Store the screen number.
		sprintf(wkbuf,"\n%4hu   ",scrp->s_num);
		strp = strchr(wkbuf,'\0');

		// List screen's window numbers and buffer names.
		wnum = 0;
		winp = scrp->s_wheadp;
		do {
			Buffer *bufp = winp->w_bufp;

			// Indent if not first time through.
			if(wnum != 0) {
				wkbuf[0] = '\n';
				strp = wkbuf + 1;
				do {
					*strp++ = ' ';
					} while(strp <= wkbuf + windcol);
				}

			// Store window number, buffer name, and filename.
			sprintf(strp,"%4u   %c%s",++wnum,(bufp->b_flags & BFCHGD) ? '*' : ' ',bufp->b_bname);
			strp = strchr(strp,'\0');
			if(bufp->b_fname != NULL)			// Pad if filename exists.
				do {
					*strp++ = ' ';
					} while(strp <= wkbuf + filecol);
			*strp = '\0';					// Save buffer and add filename.
			if(vputs(wkbuf,&rpt) != 0 ||
			 (bufp->b_fname != NULL && vputs(bufp->b_fname,&rpt) != 0))
				return vrcset();

			// On to the next window.
			} while((winp = winp->w_nextp) != NULL);

		// On to the next screen.
		} while((scrp = scrp->s_nextp) != NULL);

	// Add the results to the buffer.
	if(vclose(&rpt) != 0)
		return vrcset();
	if(bappend(slistp,rpt.sl_vp->v_strp) != SUCCESS)
		return rc.status;

	// Display results.
	return render(rp,n < 0 ? -2 : n,slistp,RENDRESET | (n != INT_MIN && n < -1 ? RENDALTML : 0));
	}