]> mj.ucw.cz Git - libucw.git/blob - ucw/time-timer.c
xtypes: added first shot on unit parser
[libucw.git] / ucw / time-timer.c
1 /*
2  *      UCW Library -- A Simple Millisecond Timer
3  *
4  *      (c) 2007--2012 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include <ucw/lib.h>
11 #include <ucw/time.h>
12
13 void
14 init_timer(timestamp_t *timer)
15 {
16   *timer = get_timestamp();
17 }
18
19 uint
20 get_timer(timestamp_t *timer)
21 {
22   timestamp_t t = *timer;
23   *timer = get_timestamp();
24   return MIN(*timer-t, ~0U);
25 }
26
27 uint
28 switch_timer(timestamp_t *oldt, timestamp_t *newt)
29 {
30   *newt = get_timestamp();
31   return MIN(*newt-*oldt, ~0U);
32 }
33
34 #ifdef TEST
35
36 #include <stdio.h>
37 #include <unistd.h>
38
39 int main(void)
40 {
41   timestamp_t t;
42   init_timer(&t);
43   usleep(50000);
44   printf("%u\n", get_timer(&t));
45   return 0;
46 }
47
48 #endif