Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

gguslumber(3) [debian man page]

ggCurTime(3)								GGI							      ggCurTime(3)

NAME
ggCurTime, ggUSleep, ggUSlumber - Portable Time Routines SYNOPSIS
#include <ggi/gg.h> int ggCurTime(struct timeval *tv); int ggUSleep(int32_t usecs); void ggUSlumber(int32_t usecs); DESCRIPTION
ggCurTime fills the timeval structure pointed to by tv with the current time to the best precision available on the executing platform. ggUSleep sleeps for at least usecs microseconds, to the best precision available on the executing platform, but may be woken up by a signal or other unspecified condition. It is not guaranteed that ggUSleep will wake up prematurely for any specific reason. It is mainly useful for points where the main objective is to avoid using CPU resources, not to perform accurate timing. ggUSlumber does the same thing as ggUSleep, but is guaranteed not to return until the allotted time has elapsed. It is slightly less effi- cient than ggUSleep with reguard to CPU utilization. All times represent wall-clock (real, versus processor) times. The above routines are often simple macros rather than functions, and as such should not be used by reference. The above functions are threadsafe, but are not guaranteed to be safe to use in a thread that may be cancelled during their execution. They are also not guaranteed to be safe to use in special contexts such as LibGG task handlers, signal handlers and asyncronous procedure calls. RETURN VALUE
ggCurTime returns GGI_OK on success, or a negative value on failure. On Windows, this function will never report a failure. On platforms where gettimeofday(2) is used, the error code is the one returned by gettimeofday. ggUSleep returns GGI_OK when the alloted time interval has elapsed, or a non-zero value if the sleep was interrupted. On platforms where usleep(3) is used, the error code is the one return by usleep. EXAMPLE
A demonstration on how to measure a framerate. struct timeval start, stop, diff; long time_of_frame = 1; int framerate; ... ggCurTime(&start); /* do something here, i.e. render and display a frame */ ggCurTime(&stop); diff.tv_sec = stop_tv.tv_sec - start_tv.tv_sec; diff.tv_usec = stop_tv.tv_usec - start_tv.tv_usec; if (diff.tv_usec < 0) { diff.tv_usec += 1000000; diff.tv_sec--; } time_of_frame = diff.tv_sec * 1000 + diff.tv_usec / 1000; if (time_of_frame == 0) time_of_frame = 1; /* CPU too fast? */ printf("framerate: %i ", 1000 / time_of_framerate); SEE ALSO
gettimeofday(2), usleep(3) libgg-1.0.x 2005-08-26 ggCurTime(3)

Check Out this Related Man Page

TIMEVAL(3)						   BSD Library Functions Manual 						TIMEVAL(3)

NAME
timeval, timespec, itimerval, itimerspec, bintime -- time structures SYNOPSIS
#include <sys/time.h> void TIMEVAL_TO_TIMESPEC(struct timeval *tv, struct timespec *ts); void TIMESPEC_TO_TIMEVAL(struct timeval *tv, struct timespec *ts); DESCRIPTION
The <sys/time.h> header, included by <time.h>, defines various structures related to time and timers. 1. The following structure is used by gettimeofday(2), among others: struct timeval { time_t tv_sec; suseconds_t tv_usec; }; The tv_sec member represents the elapsed time, in whole seconds. The tv_usec member captures rest of the elapsed time, represented as the number of microseconds. 2. The following structure is used by nanosleep(2), among others: struct timespec { time_t tv_sec; long tv_nsec; }; The tv_sec member is again the elapsed time in whole seconds. The tv_nsec member represents the rest of the elapsed time in nanosec- onds. A microsecond is equal to one millionth of a second, 1000 nanoseconds, or 1/1000 milliseconds. To ease the conversions, the macros TIMEVAL_TO_TIMESPEC() and TIMESPEC_TO_TIMEVAL() can be used to convert between struct timeval and struct timespec. 3. The following structure is used by setitimer(2), among others: struct itimerval { struct timeval it_interval; struct timeval it_value; }; 4. The following structure is used by timer_settime(2), among others: struct itimerspec { struct timespec it_interval; struct timespec it_value; }; Both struct itimerval and struct itimerspec are used to specify when a timer expires. Generally, it_interval specifies the period between successive timer expirations. A value zero implies that the alarm will fire only once. If it_value is non-zero, it indicates the time left to the next timer expiration. A value zero implies that the timer is disabled. 5. The following structure is used by bintime(9), among others: struct bintime { time_t sec; uint64_t frac; }; The sec member specifies the time in seconds and frac represents a 64-bit fraction of seconds. The struct bintime is meant to be used in the kernel only. It is further described in timecounter(9). EXAMPLES
It can be stressed that the traditional UNIX timeval and timespec structures represent elapsed time, measured by the system clock (see hz(9)). The following sketch implements a function suitable for use in a context where the timespec structure is required for a conditional timeout: static void example(struct timespec *spec, time_t minutes) { struct timeval elapsed; (void)gettimeofday(&elapsed, NULL); _DIAGASSERT(spec != NULL); TIMEVAL_TO_TIMESPEC(&elapsed, spec); /* Add the offset for timeout in minutes. */ spec->tv_sec = spec->tv_sec + minutes * 60; } A better alternative would use the more precise clock_gettime(2). SEE ALSO
timeradd(3), tm(3), bintime_add(9) BSD
April 12, 2011 BSD
Man Page