]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/clock_types.h
f05a73ec7cfbdd2c6418c2c49cb4d2992f1109a5
[apple/xnu.git] / osfmk / mach / clock_types.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * File: clock_types.h
30 * Purpose: Clock facility header definitions. These
31 * definitons are needed by both kernel and
32 * user-level software.
33 */
34
35 /*
36 * N.B. This interface has been deprecated and the contents
37 * of this file should be considered obsolete.
38 */
39
40 #ifndef _MACH_CLOCK_TYPES_H_
41 #define _MACH_CLOCK_TYPES_H_
42
43 #include <mach/time_value.h>
44 #include <sys/appleapiopts.h>
45
46 /*
47 * Type definitions.
48 */
49 typedef int alarm_type_t; /* alarm time type */
50 typedef int sleep_type_t; /* sleep time type */
51 typedef int clock_id_t; /* clock identification type */
52 typedef int clock_flavor_t; /* clock flavor type */
53 typedef int *clock_attr_t; /* clock attribute type */
54 typedef int clock_res_t; /* clock resolution type */
55
56 /*
57 * Normal time specification used by the kernel clock facility.
58 */
59 struct mach_timespec {
60 unsigned int tv_sec; /* seconds */
61 clock_res_t tv_nsec; /* nanoseconds */
62 };
63 typedef struct mach_timespec mach_timespec_t;
64
65 #ifdef __APPLE_API_UNSTABLE
66
67 /*
68 * Reserved clock id values for default clocks.
69 */
70 #define SYSTEM_CLOCK 0 /* advances monotonically and
71 * uniformly; set to zero at boot */
72 #define CALENDAR_CLOCK 1 /* 'wall' clock; effectively
73 * synchronized to UTC */
74
75 #define REALTIME_CLOCK 0 /* obsolete; use SYSTEM or CALENDAR
76 * clock depending on particular
77 * requirements */
78
79 /*
80 * Attribute names.
81 */
82 #define CLOCK_GET_TIME_RES 1 /* get_time call resolution */
83 /* 2 * was map_time call resolution */
84 #define CLOCK_ALARM_CURRES 3 /* current alarm resolution */
85 #define CLOCK_ALARM_MINRES 4 /* minimum alarm resolution */
86 #define CLOCK_ALARM_MAXRES 5 /* maximum alarm resolution */
87
88 #define NSEC_PER_USEC 1000 /* nanoseconds per microsecond */
89 #define USEC_PER_SEC 1000000 /* microseconds per second */
90 #define NSEC_PER_SEC 1000000000 /* nanoseconds per second */
91
92 #define BAD_MACH_TIMESPEC(t) \
93 ((t)->tv_nsec < 0 || (t)->tv_nsec >= NSEC_PER_SEC)
94
95 /* t1 <=> t2, also (t1 - t2) in nsec with max of +- 1 sec */
96 #define CMP_MACH_TIMESPEC(t1, t2) \
97 ((t1)->tv_sec > (t2)->tv_sec ? +NSEC_PER_SEC : \
98 ((t1)->tv_sec < (t2)->tv_sec ? -NSEC_PER_SEC : \
99 (t1)->tv_nsec - (t2)->tv_nsec))
100
101 /* t1 += t2 */
102 #define ADD_MACH_TIMESPEC(t1, t2) \
103 do { \
104 if (((t1)->tv_nsec += (t2)->tv_nsec) >= NSEC_PER_SEC) { \
105 (t1)->tv_nsec -= NSEC_PER_SEC; \
106 (t1)->tv_sec += 1; \
107 } \
108 (t1)->tv_sec += (t2)->tv_sec; \
109 } while (0)
110
111 /* t1 -= t2 */
112 #define SUB_MACH_TIMESPEC(t1, t2) \
113 do { \
114 if (((t1)->tv_nsec -= (t2)->tv_nsec) < 0) { \
115 (t1)->tv_nsec += NSEC_PER_SEC; \
116 (t1)->tv_sec -= 1; \
117 } \
118 (t1)->tv_sec -= (t2)->tv_sec; \
119 } while (0)
120
121 /*
122 * Alarm parameter defines.
123 */
124 #define ALRMTYPE 0xff /* type (8-bit field) */
125 #define TIME_ABSOLUTE 0x00 /* absolute time */
126 #define TIME_RELATIVE 0x01 /* relative time */
127
128 #define BAD_ALRMTYPE(t) (((t) &~ TIME_RELATIVE) != 0)
129
130 #endif /* __APPLE_API_UNSTABLE */
131
132 #endif /* _MACH_CLOCK_TYPES_H_ */