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