/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1991 by John E. Lloyd.				    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
/*---------------------------------------------------------------------------
 *		
 * MODULE NAME:	utility 
 *
 * DESCRIPTION:	Just some utility routines used by the 
 *		RCCL package.
 *
 * AUTHOR/DATE:	John Lloyd, Fall 1989
 *
 * MODIFICATION HISTORY:
 *
 *--------------------------------------------------------------------------*/

#include "../h/rcclDefs.h"
#include "../h/errorCodes.h"
#include "../rccl/setpoint.h"

RCCL_GMEM *rcclGmem;

RCCL_GMEM *globalMemoryCheck(fxnName)
char *fxnName;
{
	/* Check to see if the variable rcclGmem (which points to the
	   RCCL global system memory) has been set correctly for the
	   CPU we are currently executing on. If not, set it. If
	   we encounter an error, just abort ... we should not encounter
	   an error.
	 */
	extern int rciCpu;
	static int initDone = 0;
	static int gmemValid = -1;

	if (!initDone)
	 { initDone = 1;
	   gmemValid = -1;
	   requestFlagInit(&initDone);
	 }
	if (gmemValid != rciCpu)
	 { if (rciCpu == 0)
	    { if (rcclGmem == NULL)
	       { rciAbort (EFatal,"%s -- can't get global memory\n", fxnName);
		 return (NULL);
	       }
	    }
	   else
	    { if ((rcclGmem = (RCCL_GMEM*)getGlobalMemory ("RCCL_GMEM")) 
					  == NULL)
	       { rciAbort (EFatal,"%s -- can't get global memory\n", fxnName);
		 return (NULL);
	       }
	    }
	   gmemValid = rciCpu;
	 }
	return (rcclGmem);
}

delay (time)
double time;
{
	char *fxnName = "delay()";

	if (!planningLevelCheck(fxnName))
	 { return;
	 }
	nap (time/1000.0);
}
