]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/OSBase.h
b27beb1d7d7eea7892ee046947ea86bdc07b227f
[apple/xnu.git] / libkern / libkern / OSBase.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
25 *
26 * HISTORY
27 *
28 */
29
30 #ifndef _OS_OSBASE_H
31 #define _OS_OSBASE_H
32
33 #include <sys/cdefs.h>
34
35 #include <libkern/OSTypes.h>
36
37 #include <stdint.h>
38
39 __BEGIN_DECLS
40
41 #ifdef KERNEL_PRIVATE
42
43 OS_INLINE
44 uint64_t
45 __OSAbsoluteTime(
46 AbsoluteTime abstime)
47 {
48 return (*(uint64_t *)&abstime);
49 }
50
51 OS_INLINE
52 uint64_t *
53 __OSAbsoluteTimePtr(
54 AbsoluteTime *abstime)
55 {
56 return ((uint64_t *)abstime);
57 }
58
59 #define AbsoluteTime_to_scalar(x) (*(uint64_t *)(x))
60
61 /* t1 < = > t2 */
62 #define CMP_ABSOLUTETIME(t1, t2) \
63 (AbsoluteTime_to_scalar(t1) > \
64 AbsoluteTime_to_scalar(t2)? (int)+1 : \
65 (AbsoluteTime_to_scalar(t1) < \
66 AbsoluteTime_to_scalar(t2)? (int)-1 : 0))
67
68 /* t1 += t2 */
69 #define ADD_ABSOLUTETIME(t1, t2) \
70 (AbsoluteTime_to_scalar(t1) += \
71 AbsoluteTime_to_scalar(t2))
72
73 /* t1 -= t2 */
74 #define SUB_ABSOLUTETIME(t1, t2) \
75 (AbsoluteTime_to_scalar(t1) -= \
76 AbsoluteTime_to_scalar(t2))
77
78 #define ADD_ABSOLUTETIME_TICKS(t1, ticks) \
79 (AbsoluteTime_to_scalar(t1) += \
80 (int32_t)(ticks))
81
82 #endif /* KERNEL_PRIVATE */
83
84 __END_DECLS
85
86 #endif /* _OS_OSBASE_H */