Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* Project: OSLib |
2 | * Description: The OS Construction Kit |
||
3 | * Date: 1.6.2000 |
||
4 | * Idea by: Luca Abeni & Gerardo Lamastra |
||
5 | * |
||
6 | * OSLib is an SO project aimed at developing a common, easy-to-use |
||
7 | * low-level infrastructure for developing OS kernels and Embedded |
||
8 | * Applications; it partially derives from the HARTIK project but it |
||
9 | * currently is independently developed. |
||
10 | * |
||
11 | * OSLib is distributed under GPL License, and some of its code has |
||
12 | * been derived from the Linux kernel source; also some important |
||
13 | * ideas come from studying the DJGPP go32 extender. |
||
14 | * |
||
15 | * We acknowledge the Linux Community, Free Software Foundation, |
||
16 | * D.J. Delorie and all the other developers who believe in the |
||
17 | * freedom of software and ideas. |
||
18 | * |
||
19 | * For legalese, check out the included GPL license. |
||
20 | */ |
||
21 | |||
22 | /* Inline functions for managing timespec structures. |
||
23 | All timespec values are pointers!!! |
||
24 | This file defines these functions: |
||
25 | TIMESPEC2NANOSEC(t) |
||
26 | converts a timespec value to a nanosec value, and return |
||
27 | it, no checks |
||
28 | TIMESPEC2USEC(t) |
||
29 | converts a timespec value to a nanosec value, and return |
||
30 | it, no checks |
||
31 | NULL_TIMESPEC(t) |
||
32 | the timespec value is set to the Epoch (=0) |
||
33 | ADDNANO2TIMESPEC(n, t) |
||
34 | t = t + n |
||
35 | ADDUSEC2TIMESPEC(m, t) |
||
36 | t = t + m |
||
37 | SUBTIMESPEC(s1, s2, d) |
||
38 | d = s1 - s2 |
||
39 | ADDTIMESPEC(s1, s2, d) |
||
40 | d = s1 + s2 |
||
41 | TIMESPEC_A_LT_B(a,b) |
||
42 | a < b |
||
43 | TIMESPEC_A_GT_B(a,b) |
||
44 | a > b |
||
45 | TIMESPEC_A_EQ_B(a,b) |
||
46 | a == b |
||
47 | TIMESPEC_A_NEQ_B(a,b) |
||
48 | a != b |
||
49 | TIMESPEC_ASSIGN(t1,t2) |
||
50 | t1 = t2 */ |
||
51 | |||
52 | #ifndef __LL_SYS_LL_TIME_H__ |
||
53 | #define __LL_SYS_LL_TIME_H__ |
||
54 | |||
55 | #include <ll/i386/defs.h> |
||
56 | BEGIN_DEF |
||
57 | |||
58 | struct timespec { |
||
59 | long tv_sec; /* Seconds */ |
||
60 | long tv_nsec; /* Nanoseconds */ |
||
61 | }; |
||
62 | |||
63 | /* |
||
64 | * these macros come from the Utah Flux oskit... |
||
65 | */ |
||
66 | |||
67 | #define TIMESPEC2NANOSEC(t) ((t)->tv_sec * 1000000000 + (t)->tv_nsec) |
||
68 | #define TIMESPEC2USEC(t) ((t)->tv_sec * 1000000 + (t)->tv_nsec / 1000) |
||
69 | #define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0) |
||
70 | #define ADDNANO2TIMESPEC(n, t) ((t)->tv_nsec += (n), \ |
||
71 | (t)->tv_sec += (t)->tv_nsec / 1000000000, \ |
||
72 | (t)->tv_nsec %= 1000000000) |
||
73 | |||
74 | #define SUBTIMESPEC(s1, s2, d) \ |
||
75 | ((d)->tv_nsec = ((s1)->tv_nsec >= (s2)->tv_nsec) ? \ |
||
76 | (((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec), \ |
||
77 | (s1)->tv_nsec - (s2)->tv_nsec) \ |
||
78 | : \ |
||
79 | (((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec - 1), \ |
||
80 | (1000000000 + (s1)->tv_nsec - (s2)->tv_nsec))) |
||
81 | |||
82 | /* |
||
83 | * ...and these not! |
||
84 | */ |
||
85 | |||
86 | extern __inline__ void ADDTIMESPEC(const struct timespec *s1, |
||
87 | const struct timespec *s2, |
||
88 | struct timespec *d) |
||
89 | { |
||
90 | d->tv_sec = s1->tv_sec + s2->tv_sec; |
||
91 | d->tv_nsec = s1->tv_nsec + s2->tv_nsec; |
||
92 | |||
93 | if (d->tv_nsec < 0) { |
||
94 | d->tv_sec--; |
||
95 | d->tv_nsec += 1000000000; |
||
96 | } else if (d->tv_nsec >= 1000000000) { |
||
97 | d->tv_sec++; |
||
98 | d->tv_nsec -= 1000000000; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | |||
103 | #define ADDUSEC2TIMESPEC(m, t) ((t)->tv_nsec += ((m)%1000000)*1000, \ |
||
104 | (t)->tv_sec += ((t)->tv_nsec / 1000000000) + ((m)/1000000), \ |
||
105 | (t)->tv_nsec %= 1000000000) |
||
106 | |||
107 | #define TIMESPEC_A_LT_B(a,b) \ |
||
108 | ( \ |
||
109 | ((a)->tv_sec < (b)->tv_sec) || \ |
||
110 | ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec < (b)->tv_nsec) \ |
||
111 | ) |
||
112 | |||
113 | #define TIMESPEC_A_GT_B(a,b) \ |
||
114 | ( \ |
||
115 | ((a)->tv_sec > (b)->tv_sec) || \ |
||
116 | ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec > (b)->tv_nsec) \ |
||
117 | ) |
||
118 | |||
119 | #define TIMESPEC_A_EQ_B(a,b) \ |
||
120 | ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec == (b)->tv_nsec) |
||
121 | |||
122 | #define TIMESPEC_A_NEQ_B(a,b) \ |
||
123 | ((a)->tv_sec != (b)->tv_sec || (a)->tv_nsec != (b)->tv_nsec) |
||
124 | |||
125 | #define TIMESPEC_ASSIGN(t1,t2) \ |
||
126 | ((t1)->tv_sec = (t2)->tv_sec, (t1)->tv_nsec = (t2)->tv_nsec) |
||
127 | |||
128 | #if 0 |
||
129 | #define PITSPEC2TIMESPEC(a,b) \ |
||
130 | ((b)->tv_nsec = (((DWORD)((a)->units) * 1000) / 1197) * 1000, \ |
||
131 | (b)->tv_sec = ((a)->gigas * 1197) / 1000) /*, \ |
||
132 | (b)->tv_sec += (b)->tv_nsec / 1000000000, \ |
||
133 | (b)->tv_nsec %= 1000000000) */ |
||
134 | #else |
||
135 | /*#define PITSPEC2TIMESPEC(a,b) \ |
||
136 | ((b)->tv_nsec = (((DWORD)((a)->units) * 1000) / 1197) * 1000, \ |
||
137 | (b)->tv_nsec += (((a)->gigas * 1197) % 1000) * 1000000, \ |
||
138 | (b)->tv_sec = ((a)->gigas * 1197) / 1000 , \ |
||
139 | (b)->tv_sec += (b)->tv_nsec / 1000000000, \ |
||
140 | (b)->tv_nsec %= 1000000000)*/ |
||
141 | #define PITSPEC2TIMESPEC(a,b) \ |
||
142 | ((b)->tv_nsec = (((DWORD)((a)->units) * 1000) / 1197), \ |
||
143 | (b)->tv_nsec += (((a)->gigas * 1197) % 1000) * 1000, \ |
||
144 | (b)->tv_sec = ((a)->gigas * 1197) / 1000 , \ |
||
145 | (b)->tv_sec += (b)->tv_nsec / 1000000, \ |
||
146 | (b)->tv_nsec %= 1000000, \ |
||
147 | (b)->tv_nsec *= 1000) |
||
148 | #endif |
||
149 | |||
150 | TIME ll_gettime(int mode, struct timespec *tsres); |
||
151 | |||
152 | #define TIME_PTICK 1 |
||
153 | #define TIME_EXACT 2 |
||
154 | #define TIME_NEW 3 |
||
155 | |||
156 | END_DEF |
||
157 | #endif |