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