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