Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1672 | tullio | 1 | #ifndef __TIME_H__ |
2 | #define __TIME_H__ |
||
3 | |||
4 | #define TIMESPEC2NANOSEC(t) ((t)->tv_sec * 1000000000 + (t)->tv_nsec) |
||
5 | #define TIMESPEC2USEC(t) ((t)->tv_sec * 1000000 + (t)->tv_nsec / 1000) |
||
6 | #define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0) |
||
7 | #define ADDNANO2TIMESPEC(n, t) ((t)->tv_nsec += (n), \ |
||
8 | (t)->tv_sec += (t)->tv_nsec / 1000000000, \ |
||
9 | (t)->tv_nsec %= 1000000000) |
||
10 | |||
11 | #define SUBTIMESPEC(s1, s2, d) \ |
||
12 | ((d)->tv_nsec = ((s1)->tv_nsec >= (s2)->tv_nsec) ? \ |
||
13 | (((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec), \ |
||
14 | (s1)->tv_nsec - (s2)->tv_nsec) \ |
||
15 | : \ |
||
16 | (((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec - 1), \ |
||
17 | (1000000000 + (s1)->tv_nsec - (s2)->tv_nsec))) |
||
18 | |||
19 | /* |
||
20 | * ...and these not! |
||
21 | */ |
||
22 | |||
23 | extern __inline__ void ADDTIMESPEC(const struct timespec *s1, |
||
24 | const struct timespec *s2, |
||
25 | struct timespec *d) |
||
26 | { |
||
27 | d->tv_sec = s1->tv_sec + s2->tv_sec; |
||
28 | d->tv_nsec = s1->tv_nsec + s2->tv_nsec; |
||
29 | |||
30 | if (d->tv_nsec < 0) { |
||
31 | d->tv_sec--; |
||
32 | d->tv_nsec += 1000000000; |
||
33 | } else if (d->tv_nsec >= 1000000000) { |
||
34 | d->tv_sec++; |
||
35 | d->tv_nsec -= 1000000000; |
||
36 | } |
||
37 | } |
||
38 | |||
39 | |||
40 | #define ADDUSEC2TIMESPEC(m, t) ((t)->tv_nsec += (m%1000000)*1000, \ |
||
41 | (t)->tv_sec += ((t)->tv_nsec / 1000000000) + (m/1000000), \ |
||
42 | (t)->tv_nsec %= 1000000000) |
||
43 | |||
44 | #define TIMESPEC_A_LT_B(a,b) \ |
||
45 | ( \ |
||
46 | ((a)->tv_sec < (b)->tv_sec) || \ |
||
47 | ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec < (b)->tv_nsec) \ |
||
48 | ) |
||
49 | |||
50 | #define TIMESPEC_A_GT_B(a,b) \ |
||
51 | ( \ |
||
52 | ((a)->tv_sec > (b)->tv_sec) || \ |
||
53 | ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec > (b)->tv_nsec) \ |
||
54 | ) |
||
55 | |||
56 | #define TIMESPEC_A_EQ_B(a,b) \ |
||
57 | ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec == (b)->tv_nsec) |
||
58 | |||
59 | #define TIMESPEC_A_NEQ_B(a,b) \ |
||
60 | ((a)->tv_sec != (b)->tv_sec || (a)->tv_nsec != (b)->tv_nsec) |
||
61 | |||
62 | #define TIMESPEC_ASSIGN(t1,t2) \ |
||
63 | ((t1)->tv_sec = (t2)->tv_sec, (t1)->tv_nsec = (t2)->tv_nsec) |
||
64 | |||
65 | #endif |