1ggCurTime(3)                          GGI                         ggCurTime(3)
2
3
4

NAME

6       ggCurTime, ggUSleep, ggUSlumber : Portable Time Routines
7

SYNOPSIS

9       #include <ggi/gg.h>
10
11       int ggCurTime(struct timeval *tv);
12
13       int ggUSleep(int32_t usecs);
14
15       void ggUSlumber(int32_t usecs);
16
17

DESCRIPTION

19       ggCurTime fills the timeval structure pointed to by tv with the current
20       time to the best precision available on the executing platform.
21
22       ggUSleep sleeps for at least usecs microseconds, to the best  precision
23       available on the executing platform, but may be woken up by a signal or
24       other unspecified condition.  It is not guaranteed that  ggUSleep  will
25       wake  up  prematurely for any specific reason.  It is mainly useful for
26       points where the main objective is to avoid using CPU resources, not to
27       perform accurate timing.
28
29       ggUSlumber  does  the  same thing as ggUSleep, but is guaranteed not to
30       return until the allotted time has elapsed.  It is slightly less  effi‐
31       cient than ggUSleep with reguard to CPU utilization.
32
33       All times represent wall-clock (real, versus processor) times.
34
35       The  above  routines are often simple macros rather than functions, and
36       as such should not be used by reference.
37
38       The above functions are threadsafe, but are not guaranteed to  be  safe
39       to  use in a thread that may be cancelled during their execution.  They
40       are also not guaranteed to be safe to use in special contexts  such  as
41       LibGG task handlers, signal handlers and asyncronous procedure calls.
42

RETURN VALUE

44       ggCurTime returns GGI_OK on success, or a negative value on failure. On
45       Windows, this function will never report a failure.  On platforms where
46       gettimeofday(2) is used, the error code is the one returned by gettime‐
47       ofday.
48
49       ggUSleep returns GGI_OK when the alloted time interval has elapsed,  or
50       a  non-zero  value  if  the  sleep  was interrupted. On platforms where
51       usleep(3) is used, the error code is the one return by usleep.
52

EXAMPLE

54       A demonstration on how to measure a framerate.
55
56       struct timeval start, stop, diff;
57       long time_of_frame = 1;
58       int framerate;
59
60
61       ggCurTime(&start);
62
63       /* do something here, i.e. render and display a frame */
64
65       ggCurTime(&stop);
66       diff.tv_sec = stop_tv.tv_sec - start_tv.tv_sec;
67       diff.tv_usec = stop_tv.tv_usec - start_tv.tv_usec;
68
69       if (diff.tv_usec < 0) {
70               diff.tv_usec += 1000000;
71               diff.tv_sec--;
72       }
73       time_of_frame = diff.tv_sec * 1000 + diff.tv_usec / 1000;
74       if (time_of_frame == 0)
75               time_of_frame = 1;      /* CPU too fast? */
76       printf("framerate: %i\n", 1000 / time_of_framerate);
77
78

SEE ALSO

80       gettimeofday(2), usleep(3)
81
82
83
84libgg-1.0.x                       2005-08-26                      ggCurTime(3)
Impressum