Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

time.C

Go to the documentation of this file.
00001 /*
00002  *  time.C: Interface to some standard UNIX time functions.
00003  *
00004  *          WARNING! -- the "standard" functions are anything but standard,.
00005  *                      They may be both non-portable and subject to change!
00006  *
00007  *                      The code below is tested only in SunOS 4.1.3 and HPUX.
00008  *
00009  *.............................................................................
00010  *    version 1:  Mar 1994   Steve McMillan
00011  *    version 2:  
00012  *.............................................................................
00013  *  non-local functions: 
00014  *    cpu_time
00015  *.............................................................................
00016  */
00017 
00018 #include "stdinc.h"
00019 
00020 #ifndef NO_CPU_TIME
00021 #   include <sys/times.h>
00022     struct tms buffer;
00023 #   include <unistd.h>
00024     static long ticks_per_sec = 0;
00025 #endif
00026 
00027 #ifndef NO_CPU_TIME
00028   static real initial_cpu = 0;
00029 #endif
00030 
00031 //-----------------------------------------------------------------------------
00032 //  cpu_init: initialize the CPU timer.
00033 //-----------------------------------------------------------------------------
00034 
00035 void cpu_init()
00036 {
00037 #ifndef NO_CPU_TIME
00038     times(&buffer);
00039 
00040     // Use both system and user time because of ambiguities
00041     // with Linux multiprocessing...
00042 
00043     initial_cpu = (real) (buffer.tms_utime + buffer.tms_stime);
00044 
00045     ticks_per_sec = sysconf(_SC_CLK_TCK);       // Clock ticks per second
00046 #endif
00047 }
00048 
00049 //-----------------------------------------------------------------------------
00050 //  cpu_time: return total processor time (in seconds) used since the timer
00051 //            was last initialized by a call to cpu_init.
00052 //-----------------------------------------------------------------------------
00053 
00054 real cpu_time()
00055 {
00056 #ifndef NO_CPU_TIME
00057 
00058     if (!ticks_per_sec)
00059         cpu_init();
00060 
00061     times(&buffer);
00062     return ((real) (buffer.tms_utime + buffer.tms_stime - initial_cpu))
00063                         / ticks_per_sec;
00064 #else
00065     return 0;
00066 #endif
00067 }
00068 
00069 // STARLAB_WAIT:        Wait a specified number of microseconds.
00070 
00071 #ifdef HAS_NANOSLEEP
00072 #include <time.h>
00073 #endif
00074 
00075 void starlab_wait(int iwait)
00076 {
00077 #ifdef HAS_USLEEP
00078     usleep(iwait);
00079 #else
00080 #ifdef HAS_NANOSLEEP
00081     timespec wait_time;
00082     twait_ime.tv_nsec = 1000*iwait;
00083     nanosleep(wait_time);
00084 #endif
00085 #endif
00086 }

Generated at Sun Feb 24 09:57:19 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001