u_time.h File Reference

OS independent time-manipulation functions. More...

Include dependency graph for u_time.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  util_time
 Time abstraction. More...

Functions

void util_time_get (struct util_time *t)
void util_time_add (const struct util_time *t1, int64_t usecs, struct util_time *t2)
uint64_t util_time_micros (void)
int64_t util_time_diff (const struct util_time *t1, const struct util_time *t2)
boolean util_time_timeout (const struct util_time *start, const struct util_time *end, const struct util_time *curr)
 Returns non-zero when the timeout expires.
void util_time_sleep (unsigned usecs)


Detailed Description

OS independent time-manipulation functions.

Author:
Jose Fonseca <jrfonseca@tungstengraphics.com>

Definition in file u_time.h.


Function Documentation

void util_time_add ( const struct util_time t1,
int64_t  usecs,
struct util_time t2 
)

Definition at line 101 of file u_time.c.

References util_time::counter.

00104 {
00105 #if defined(PIPE_OS_LINUX)
00106    t2->tv.tv_sec = t1->tv.tv_sec + usecs / 1000000;
00107    t2->tv.tv_usec = t1->tv.tv_usec + usecs % 1000000;
00108 #elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
00109    util_time_get_frequency();
00110    t2->counter = t1->counter + (usecs * frequency + INT64_C(999999))/INT64_C(1000000);
00111 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
00112    /* 1 tick = 100 nano seconds. */
00113    t2->counter = t1->counter + usecs * 10;
00114 #else
00115    LARGE_INTEGER temp;
00116    LONGLONG freq;
00117    freq = temp.QuadPart;
00118    t2->counter = t1->counter + (usecs * freq)/1000000L;
00119 #endif
00120 }

int64_t util_time_diff ( const struct util_time t1,
const struct util_time t2 
)

Definition at line 124 of file u_time.c.

References util_time::counter.

00126 {
00127 #if defined(PIPE_OS_LINUX)
00128    return (t2->tv.tv_usec - t1->tv.tv_usec) + 
00129           (t2->tv.tv_sec - t1->tv.tv_sec)*1000000;
00130 #elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
00131    util_time_get_frequency();
00132    return (t2->counter - t1->counter)*INT64_C(1000000)/frequency;
00133 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
00134    return (t2->counter - t1->counter)/10;
00135 #endif
00136 }

void util_time_get ( struct util_time t  ) 

Definition at line 78 of file u_time.c.

References util_time::counter.

00079 {
00080 #if defined(PIPE_OS_LINUX)
00081    gettimeofday(&t->tv, NULL);
00082 #elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
00083    LONGLONG temp;
00084    EngQueryPerformanceCounter(&temp);
00085    t->counter = temp;
00086 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
00087    /* Updated every 10 miliseconds, measured in units of 100 nanoseconds.
00088     * http://msdn.microsoft.com/en-us/library/ms801642.aspx */
00089    LARGE_INTEGER temp;
00090    KeQuerySystemTime(&temp);
00091    t->counter = temp.QuadPart;
00092 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
00093    LARGE_INTEGER temp;
00094    QueryPerformanceCounter(&temp);
00095    t->counter = temp.QuadPart;
00096 #endif
00097 }

uint64_t util_time_micros ( void   ) 

Definition at line 141 of file u_time.c.

References util_time::counter, and util_time_get().

00142 {
00143    struct util_time t1;
00144    
00145    util_time_get(&t1);
00146    
00147 #if defined(PIPE_OS_LINUX)
00148    return t1.tv.tv_usec + t1.tv.tv_sec*1000000LL;
00149 #elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
00150    util_time_get_frequency();
00151    return t1.counter*INT64_C(1000000)/frequency;
00152 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
00153    return t1.counter/10;
00154 #endif
00155 }

void util_time_sleep ( unsigned  usecs  ) 

boolean util_time_timeout ( const struct util_time start,
const struct util_time end,
const struct util_time curr 
)

Returns non-zero when the timeout expires.

Definition at line 192 of file u_time.c.

References util_time_compare().

00195 {
00196    if(util_time_compare(start, end) <= 0)
00197       return !(util_time_compare(start, curr) <= 0 && util_time_compare(curr, end) < 0);
00198    else
00199       return !(util_time_compare(start, curr) <= 0 || util_time_compare(curr, end) < 0);
00200 }


Generated on Tue Sep 29 06:25:30 2009 for Gallium3D by  doxygen 1.5.4