Whamcloud - gitweb
LU-1347 build: remove the vim/emacs modelines
[fs/lustre-release.git] / libcfs / include / libcfs / darwin / darwin-types.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * libcfs/include/libcfs/darwin/darwin-types.h
35  *
36  * Basic library routines.
37  */
38
39 #ifndef __LIBCFS_DARWIN_XNU_TYPES_H__
40 #define __LIBCFS_DARWIN_XNU_TYPES_H__
41
42 #ifndef __LIBCFS_LIBCFS_H__
43 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
44 #endif
45
46 #include <mach/mach_types.h>
47 #include <sys/types.h>
48
49 #ifndef _BLKID_TYPES_H
50 #define _BLKID_TYPES_H
51 #endif
52
53 typedef u_int8_t        __u8;
54 typedef u_int16_t       __u16;
55 typedef u_int32_t       __u32;
56 typedef u_int64_t       __u64;
57 typedef int8_t          __s8;
58 typedef int16_t         __s16;
59 typedef int32_t         __s32;
60 typedef int64_t         __s64;
61
62 /* long integer with size equal to pointer */
63 typedef unsigned long ulong_ptr_t;
64 typedef long long_ptr_t;
65
66 #ifdef __KERNEL__
67
68 #include <kern/kern_types.h>
69
70
71 typedef struct { int e; }               event_chan_t;
72 typedef dev_t                           kdev_t;
73
74 /*
75  * Atmoic define
76  */
77 #include <libkern/OSAtomic.h>
78
79 typedef struct { volatile uint32_t counter; }   atomic_t;
80
81 #define ATOMIC_INIT(i)                  { (i) }
82 #define atomic_read(a)                  ((a)->counter)
83 #define atomic_set(a, v)                (((a)->counter) = (v))
84 #ifdef __DARWIN8__
85 /* OS*Atomic return the value before the operation */
86 #define atomic_add(v, a)                OSAddAtomic(v, (SInt32 *)&((a)->counter))
87 #define atomic_sub(v, a)                OSAddAtomic(-(v), (SInt32 *)&((a)->counter))
88 #define atomic_inc(a)                   OSIncrementAtomic((SInt32 *)&((a)->counter))
89 #define atomic_dec(a)                   OSDecrementAtomic((SInt32 *)&((a)->counter))
90 #else /* !__DARWIN8__ */
91 #define atomic_add(v, a)                hw_atomic_add((__u32 *)&((a)->counter), v)
92 #define atomic_sub(v, a)                hw_atomic_sub((__u32 *)&((a)->counter), v)
93 #define atomic_inc(a)                   atomic_add(1, a)
94 #define atomic_dec(a)                   atomic_sub(1, a)
95 #endif /* !__DARWIN8__ */
96 #define atomic_sub_and_test(v, a)       (atomic_sub(v, a) == (v))
97 #define atomic_dec_and_test(a)          (atomic_dec(a) == 1)
98 #define atomic_inc_return(a)            (atomic_inc(a) + 1)
99 #define atomic_dec_return(a)            (atomic_dec(a) - 1)
100
101 #include <libsa/mach/mach.h>
102 typedef off_t                           loff_t;
103
104 #else   /* !__KERNEL__ */
105
106 #include <stdint.h>
107
108 typedef off_t                           loff_t;
109
110 #endif  /* __KERNEL END */
111 typedef unsigned short                  umode_t;
112
113 #endif  /* __XNU_CFS_TYPES_H__ */