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