Print this page
remove support for non-ANSI compilation
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/time.h
+++ new/usr/src/uts/common/sys/time.h
1 1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
2 2 /* All Rights Reserved */
3 3
4 4
5 5 /*
6 6 * Copyright (c) 1982, 1986, 1993 Regents of the University of California.
7 7 * All rights reserved. The Berkeley software License Agreement
8 8 * specifies the terms and conditions for redistribution.
9 9 */
10 10
11 11 /*
12 + * Copyright 2014 Garrett D'Amore <garrett@damore.org>
13 + *
12 14 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
13 15 * Use is subject to license terms.
14 16 */
15 17
16 18 #ifndef _SYS_TIME_H
17 19 #define _SYS_TIME_H
18 20
19 21 #include <sys/feature_tests.h>
20 22
21 23 /*
22 24 * Structure returned by gettimeofday(2) system call,
23 25 * and used in other calls.
24 26 */
25 27
26 28 #ifdef __cplusplus
27 29 extern "C" {
28 30 #endif
29 31
30 32 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
31 33 defined(__EXTENSIONS__)
32 34 #ifndef _ASM
33 35
34 36 #if !defined(_TIME_T) || __cplusplus >= 199711L
35 37 #define _TIME_T
36 38 typedef long time_t; /* time of day in seconds */
37 39 #endif /* _TIME_T */
38 40
39 41 #ifndef _SUSECONDS_T
40 42 #define _SUSECONDS_T
41 43 typedef long suseconds_t; /* signed # of microseconds */
42 44 #endif /* _SUSECONDS_T */
43 45
44 46 struct timeval {
45 47 time_t tv_sec; /* seconds */
46 48 suseconds_t tv_usec; /* and microseconds */
47 49 };
48 50
49 51 #if defined(_SYSCALL32)
50 52
51 53 #include <sys/types32.h>
52 54
53 55 #define TIMEVAL32_TO_TIMEVAL(tv, tv32) { \
54 56 (tv)->tv_sec = (time_t)(tv32)->tv_sec; \
55 57 (tv)->tv_usec = (tv32)->tv_usec; \
56 58 }
57 59
58 60 #define TIMEVAL_TO_TIMEVAL32(tv32, tv) { \
59 61 (tv32)->tv_sec = (time32_t)(tv)->tv_sec; \
60 62 (tv32)->tv_usec = (tv)->tv_usec; \
61 63 }
62 64
63 65 #define TIME32_MAX INT32_MAX
64 66 #define TIME32_MIN INT32_MIN
65 67
66 68 #define TIMEVAL_OVERFLOW(tv) \
67 69 ((tv)->tv_sec < TIME32_MIN || (tv)->tv_sec > TIME32_MAX)
68 70
69 71 #endif /* _SYSCALL32 || _KERNEL */
70 72
71 73 #endif /* _ASM */
72 74 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
73 75
74 76 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
75 77 #ifndef _ASM
76 78 struct timezone {
77 79 int tz_minuteswest; /* minutes west of Greenwich */
78 80 int tz_dsttime; /* type of dst correction */
79 81 };
80 82
81 83 #endif /* _ASM */
82 84 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
83 85
84 86 #ifdef __cplusplus
85 87 }
86 88 #endif
87 89
88 90 /*
89 91 * Needed for longlong_t type. Placement of this due to <sys/types.h>
90 92 * including <sys/select.h> which relies on the presense of the itimerval
91 93 * structure.
92 94 */
93 95 #ifndef _ASM
94 96 #include <sys/types.h>
95 97 #endif /* _ASM */
96 98
97 99 #ifdef __cplusplus
98 100 extern "C" {
99 101 #endif
100 102
101 103 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
102 104
103 105 #define DST_NONE 0 /* not on dst */
104 106 #define DST_USA 1 /* USA style dst */
105 107 #define DST_AUST 2 /* Australian style dst */
106 108 #define DST_WET 3 /* Western European dst */
107 109 #define DST_MET 4 /* Middle European dst */
108 110 #define DST_EET 5 /* Eastern European dst */
109 111 #define DST_CAN 6 /* Canada */
110 112 #define DST_GB 7 /* Great Britain and Eire */
111 113 #define DST_RUM 8 /* Rumania */
112 114 #define DST_TUR 9 /* Turkey */
113 115 #define DST_AUSTALT 10 /* Australian style with shift in 1986 */
114 116
115 117 /*
116 118 * Operations on timevals.
117 119 */
118 120 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
119 121 #define timercmp(tvp, uvp, cmp) \
120 122 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
121 123 /* CSTYLED */ \
122 124 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
123 125 /* CSTYLED */ \
124 126 ((tvp)->tv_sec cmp (uvp)->tv_sec))
125 127
126 128 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
127 129
128 130 #ifdef __lint
129 131 /*
130 132 * Make innocuous, lint-happy versions until do {} while (0) is acknowleged as
131 133 * lint-safe. If the compiler could know that we always make tv_usec < 1000000
132 134 * we wouldn't need a special linted version.
133 135 */
134 136 #define timeradd(tvp, uvp, vvp) \
135 137 do \
136 138 { \
137 139 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
138 140 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
139 141 if ((vvp)->tv_usec >= 1000000) \
140 142 { \
141 143 (vvp)->tv_sec++; \
142 144 (vvp)->tv_usec -= 1000000; \
143 145 } \
144 146 } while ((vvp)->tv_usec >= 1000000)
145 147 #define timersub(tvp, uvp, vvp) \
146 148 do \
147 149 { \
148 150 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
149 151 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
150 152 if ((vvp)->tv_usec < 0) \
151 153 { \
152 154 (vvp)->tv_sec--; \
153 155 (vvp)->tv_usec += 1000000; \
154 156 } \
155 157 } while ((vvp)->tv_usec >= 1000000)
156 158 #else
157 159 #define timeradd(tvp, uvp, vvp) \
158 160 do \
159 161 { \
160 162 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
161 163 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
162 164 if ((vvp)->tv_usec >= 1000000) \
163 165 { \
164 166 (vvp)->tv_sec++; \
165 167 (vvp)->tv_usec -= 1000000; \
166 168 } \
167 169 } while (0)
168 170
169 171 #define timersub(tvp, uvp, vvp) \
170 172 do \
171 173 { \
172 174 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
173 175 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
174 176 if ((vvp)->tv_usec < 0) \
175 177 { \
176 178 (vvp)->tv_sec--; \
177 179 (vvp)->tv_usec += 1000000; \
178 180 } \
179 181 } while (0)
180 182 #endif /* __lint */
181 183
182 184 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
183 185
184 186 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
185 187 /*
186 188 * Names of the interval timers, and structure
187 189 * defining a timer setting.
188 190 */
189 191 #define ITIMER_REAL 0 /* Decrements in real time */
190 192 #define ITIMER_VIRTUAL 1 /* Decrements in process virtual time */
191 193 #define ITIMER_PROF 2 /* Decrements both in process virtual */
192 194 /* time and when system is running on */
193 195 /* behalf of the process. */
194 196 #define ITIMER_REALPROF 3 /* Decrements in real time for real- */
195 197 /* time profiling of multithreaded */
196 198 /* programs. */
197 199
198 200 #ifndef _ASM
199 201 struct itimerval {
200 202 struct timeval it_interval; /* timer interval */
201 203 struct timeval it_value; /* current value */
202 204 };
203 205
204 206 #if defined(_SYSCALL32)
205 207
206 208 struct itimerval32 {
207 209 struct timeval32 it_interval;
208 210 struct timeval32 it_value;
209 211 };
210 212
211 213 #define ITIMERVAL32_TO_ITIMERVAL(itv, itv32) { \
212 214 TIMEVAL32_TO_TIMEVAL(&(itv)->it_interval, &(itv32)->it_interval); \
213 215 TIMEVAL32_TO_TIMEVAL(&(itv)->it_value, &(itv32)->it_value); \
214 216 }
215 217
216 218 #define ITIMERVAL_TO_ITIMERVAL32(itv32, itv) { \
217 219 TIMEVAL_TO_TIMEVAL32(&(itv32)->it_interval, &(itv)->it_interval); \
218 220 TIMEVAL_TO_TIMEVAL32(&(itv32)->it_value, &(itv)->it_value); \
219 221 }
220 222
221 223 #define ITIMERVAL_OVERFLOW(itv) \
222 224 (TIMEVAL_OVERFLOW(&(itv)->it_interval) || \
223 225 TIMEVAL_OVERFLOW(&(itv)->it_value))
224 226
225 227 #endif /* _SYSCALL32 */
226 228 #endif /* _ASM */
227 229 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
228 230
229 231
230 232 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
231 233 /*
232 234 * Definitions for commonly used resolutions.
233 235 */
234 236 #define SEC 1
235 237 #define MILLISEC 1000
236 238 #define MICROSEC 1000000
237 239 #define NANOSEC 1000000000LL
238 240
239 241 #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
240 242 #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
241 243
242 244 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
243 245
244 246 #ifndef _ASM
245 247
246 248 /*
247 249 * Time expressed as a 64-bit nanosecond counter.
248 250 */
249 251 typedef longlong_t hrtime_t;
250 252
251 253 #ifdef _KERNEL
252 254
253 255 #include <sys/time_impl.h>
254 256 #include <sys/mutex.h>
255 257
256 258 extern int tick_per_msec; /* clock ticks per millisecond (may be zero) */
257 259 extern int msec_per_tick; /* milliseconds per clock tick (may be zero) */
258 260 extern int usec_per_tick; /* microseconds per clock tick */
259 261 extern int nsec_per_tick; /* nanoseconds per clock tick */
260 262
261 263 /*
262 264 * Macros to convert from common units of time (sec, msec, usec, nsec,
263 265 * timeval, timestruc) to clock ticks and vice versa.
264 266 */
265 267 #define TICK_TO_SEC(tick) ((tick) / hz)
266 268 #define SEC_TO_TICK(sec) ((sec) * hz)
267 269
268 270 #define TICK_TO_MSEC(tick) \
269 271 (msec_per_tick ? (tick) * msec_per_tick : (tick) / tick_per_msec)
270 272 #define MSEC_TO_TICK(msec) \
271 273 (msec_per_tick ? (msec) / msec_per_tick : (msec) * tick_per_msec)
272 274 #define MSEC_TO_TICK_ROUNDUP(msec) \
273 275 (msec_per_tick ? \
274 276 ((msec) == 0 ? 0 : ((msec) - 1) / msec_per_tick + 1) : \
275 277 (msec) * tick_per_msec)
276 278
277 279 #define TICK_TO_USEC(tick) ((tick) * usec_per_tick)
278 280 #define USEC_TO_TICK(usec) ((usec) / usec_per_tick)
279 281 #define USEC_TO_TICK_ROUNDUP(usec) \
280 282 ((usec) == 0 ? 0 : USEC_TO_TICK((usec) - 1) + 1)
281 283
282 284 #define TICK_TO_NSEC(tick) ((hrtime_t)(tick) * nsec_per_tick)
283 285 #define NSEC_TO_TICK(nsec) ((nsec) / nsec_per_tick)
284 286 #define NSEC_TO_TICK_ROUNDUP(nsec) \
285 287 ((nsec) == 0 ? 0 : NSEC_TO_TICK((nsec) - 1) + 1)
286 288
287 289 #define TICK_TO_TIMEVAL(tick, tvp) { \
288 290 clock_t __tmptck = (tick); \
289 291 (tvp)->tv_sec = TICK_TO_SEC(__tmptck); \
290 292 (tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK((tvp)->tv_sec)); \
291 293 }
292 294
293 295 #define TICK_TO_TIMEVAL32(tick, tvp) { \
294 296 clock_t __tmptck = (tick); \
295 297 time_t __tmptm = TICK_TO_SEC(__tmptck); \
296 298 (tvp)->tv_sec = (time32_t)__tmptm; \
297 299 (tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK(__tmptm)); \
298 300 }
299 301
300 302 #define TICK_TO_TIMESTRUC(tick, tsp) { \
301 303 clock_t __tmptck = (tick); \
302 304 (tsp)->tv_sec = TICK_TO_SEC(__tmptck); \
303 305 (tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK((tsp)->tv_sec)); \
304 306 }
305 307
306 308 #define TICK_TO_TIMESTRUC32(tick, tsp) { \
307 309 clock_t __tmptck = (tick); \
308 310 time_t __tmptm = TICK_TO_SEC(__tmptck); \
309 311 (tsp)->tv_sec = (time32_t)__tmptm; \
310 312 (tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK(__tmptm)); \
311 313 }
312 314
313 315 #define TIMEVAL_TO_TICK(tvp) \
314 316 (SEC_TO_TICK((tvp)->tv_sec) + USEC_TO_TICK((tvp)->tv_usec))
315 317
316 318 #define TIMESTRUC_TO_TICK(tsp) \
317 319 (SEC_TO_TICK((tsp)->tv_sec) + NSEC_TO_TICK((tsp)->tv_nsec))
318 320
319 321 typedef struct todinfo {
320 322 int tod_sec; /* seconds 0-59 */
321 323 int tod_min; /* minutes 0-59 */
322 324 int tod_hour; /* hours 0-23 */
323 325 int tod_dow; /* day of week 1-7 */
324 326 int tod_day; /* day of month 1-31 */
325 327 int tod_month; /* month 1-12 */
326 328 int tod_year; /* year 70+ */
327 329 } todinfo_t;
328 330
329 331 extern int64_t timedelta;
330 332 extern int timechanged;
331 333 extern int tod_needsync;
332 334 extern kmutex_t tod_lock;
333 335 extern volatile timestruc_t hrestime;
334 336 extern hrtime_t hres_last_tick;
335 337 extern int64_t hrestime_adj;
336 338 extern uint_t adj_shift;
337 339
338 340 extern timestruc_t tod_get(void);
339 341 extern void tod_set(timestruc_t);
340 342 extern void set_hrestime(timestruc_t *);
341 343 extern todinfo_t utc_to_tod(time_t);
342 344 extern time_t tod_to_utc(todinfo_t);
343 345 extern int hr_clock_lock(void);
344 346 extern void hr_clock_unlock(int);
345 347 extern hrtime_t gethrtime(void);
346 348 extern hrtime_t gethrtime_unscaled(void);
347 349 extern hrtime_t gethrtime_max(void);
348 350 extern hrtime_t gethrtime_waitfree(void);
349 351 extern void scalehrtime(hrtime_t *);
350 352 extern uint64_t unscalehrtime(hrtime_t);
351 353 extern void gethrestime(timespec_t *);
352 354 extern time_t gethrestime_sec(void);
353 355 extern void gethrestime_lasttick(timespec_t *);
354 356 extern void hrt2ts(hrtime_t, timestruc_t *);
355 357 extern hrtime_t ts2hrt(const timestruc_t *);
356 358 extern void hrt2tv(hrtime_t, struct timeval *);
357 359 extern hrtime_t tv2hrt(struct timeval *);
358 360 extern int itimerfix(struct timeval *, int);
359 361 extern int itimerdecr(struct itimerval *, int);
360 362 extern void timevaladd(struct timeval *, struct timeval *);
361 363 extern void timevalsub(struct timeval *, struct timeval *);
362 364 extern void timevalfix(struct timeval *);
363 365 extern void dtrace_hres_tick(void);
364 366
↓ open down ↓ |
343 lines elided |
↑ open up ↑ |
365 367 extern clock_t ddi_get_lbolt(void);
366 368 extern int64_t ddi_get_lbolt64(void);
367 369
368 370 #if defined(_SYSCALL32)
369 371 extern void hrt2ts32(hrtime_t, timestruc32_t *);
370 372 #endif
371 373
372 374 #endif /* _KERNEL */
373 375
374 376 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
375 -#if defined(__STDC__)
376 377 int adjtime(struct timeval *, struct timeval *);
377 -#else
378 -int adjtime();
379 -#endif
380 378 #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
381 379
382 380 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || \
383 381 defined(_ATFILE_SOURCE) || defined(__EXTENSIONS__)
384 -#if defined(__STDC__)
385 382 int futimesat(int, const char *, const struct timeval *);
386 -#else
387 -int futimesat();
388 -#endif /* defined(__STDC__) */
389 383 #endif /* defined(__ATFILE_SOURCE) */
390 384
391 385 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
392 386 defined(__EXTENSIONS__)
393 387
394 -#if defined(__STDC__)
395 -
396 388 int getitimer(int, struct itimerval *);
397 389 int utimes(const char *, const struct timeval *);
398 390 #if defined(_XPG4_2)
399 391 int setitimer(int, const struct itimerval *_RESTRICT_KYWD,
400 392 struct itimerval *_RESTRICT_KYWD);
401 393 #else
402 394 int setitimer(int, struct itimerval *_RESTRICT_KYWD,
403 395 struct itimerval *_RESTRICT_KYWD);
404 396 #endif /* defined(_XPG2_2) */
405 397
406 -#else /* __STDC__ */
407 -
408 -int gettimer();
409 -int settimer();
410 -int utimes();
411 -#endif /* __STDC__ */
412 398 #endif /* !defined(_KERNEL) ... defined(_XPG4_2) */
413 399
414 400 /*
415 401 * gettimeofday() and settimeofday() were included in SVr4 due to their
416 402 * common use in BSD based applications. They were to be included exactly
417 403 * as in BSD, with two parameters. However, AT&T/USL noted that the second
418 404 * parameter was unused and deleted it, thereby making a routine included
419 405 * for compatibility, incompatible.
420 406 *
421 407 * XSH4.2 (spec 1170) defines gettimeofday and settimeofday to have two
422 408 * parameters.
423 409 *
424 410 * This has caused general disagreement in the application community as to
425 411 * the syntax of these routines. Solaris defaults to the XSH4.2 definition.
426 412 * The flag _SVID_GETTOD may be used to force the SVID version.
427 413 */
428 414 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
429 415
430 -#if defined(__STDC__)
431 416 #if defined(_SVID_GETTOD)
432 417 int settimeofday(struct timeval *);
433 418 #else
434 419 int settimeofday(struct timeval *, void *);
435 420 #endif
436 421 hrtime_t gethrtime(void);
437 422 hrtime_t gethrvtime(void);
438 -#else /* __STDC__ */
439 -int settimeofday();
440 -hrtime_t gethrtime();
441 -hrtime_t gethrvtime();
442 -#endif /* __STDC__ */
443 423
444 424 #endif /* !(defined _KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
445 425
446 426 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
447 427 defined(__EXTENSIONS__)
448 428
449 -#if defined(__STDC__)
450 429 #if defined(_SVID_GETTOD)
451 430 int gettimeofday(struct timeval *);
452 431 #else
453 432 int gettimeofday(struct timeval *_RESTRICT_KYWD, void *_RESTRICT_KYWD);
454 433 #endif
455 -#else /* __STDC__ */
456 -int gettimeofday();
457 -#endif /* __STDC__ */
458 434
459 435 #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
460 436
461 437 /*
462 438 * The inclusion of <time.h> is historical and was added for
463 439 * backward compatibility in delta 1.2 when a number of definitions
464 440 * were moved out of <sys/time.h>. More recently, the timespec and
465 441 * itimerspec structure definitions, along with the _CLOCK_*, CLOCK_*,
466 442 * _TIMER_*, and TIMER_* symbols were moved to <sys/time_impl.h>,
467 443 * which is now included by <time.h>. This change was due to POSIX
468 444 * 1003.1b-1993 and X/Open UNIX 98 requirements. For non-POSIX and
469 445 * non-X/Open applications, including this header will still make
470 446 * visible these definitions.
471 447 */
472 448 #if !defined(_BOOT) && !defined(_KERNEL) && \
473 449 !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
474 450 #include <time.h>
475 451 #endif
476 452
477 453 /*
478 454 * The inclusion of <sys/select.h> is needed for the FD_CLR,
479 455 * FD_ISSET, FD_SET, and FD_SETSIZE macros as well as the
480 456 * select() prototype defined in the XOpen specifications
481 457 * beginning with XSH4v2. Placement required after definition
482 458 * for itimerval.
483 459 */
484 460 #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
485 461 defined(__EXTENSIONS__)
486 462 #include <sys/select.h>
487 463 #endif
488 464
489 465 #endif /* _ASM */
490 466
491 467 #ifdef __cplusplus
492 468 }
493 469 #endif
494 470
495 471 #endif /* _SYS_TIME_H */
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX