Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lnet / 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  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Basic library routines. 
22  *
23  */
24
25 #ifndef __LIBCFS_DARWIN_XNU_TYPES_H__
26 #define __LIBCFS_DARWIN_XNU_TYPES_H__
27
28 #ifndef __LIBCFS_LIBCFS_H__
29 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
30 #endif
31
32 #include <mach/mach_types.h>
33 #include <sys/types.h>
34
35 #ifndef _BLKID_TYPES_H
36 #define _BLKID_TYPES_H
37 #endif
38
39 typedef u_int8_t        __u8;
40 typedef u_int16_t       __u16;
41 typedef u_int32_t       __u32;
42 typedef u_int64_t       __u64;
43 typedef int8_t          __s8;
44 typedef int16_t         __s16;
45 typedef int32_t         __s32;
46 typedef int64_t         __s64;
47
48 #ifdef __KERNEL__
49
50 #include <kern/kern_types.h>
51
52
53 typedef struct { int e; }               event_chan_t;
54 typedef dev_t                           kdev_t;
55
56 /*
57  * Atmoic define
58  */
59 #include <libkern/OSAtomic.h>
60
61 typedef struct { volatile uint32_t counter; }   atomic_t;
62
63 #define ATOMIC_INIT(i)                  { (i) }
64 #define atomic_read(a)                  ((a)->counter)
65 #define atomic_set(a, v)                (((a)->counter) = (v))
66 #ifdef __DARWIN8__
67 /* OS*Atomic return the value before the operation */
68 #define atomic_add(v, a)                OSAddAtomic(v, (SInt32 *)&((a)->counter))
69 #define atomic_sub(v, a)                OSAddAtomic(-(v), (SInt32 *)&((a)->counter))
70 #define atomic_inc(a)                   OSIncrementAtomic((SInt32 *)&((a)->counter))
71 #define atomic_dec(a)                   OSDecrementAtomic((SInt32 *)&((a)->counter))
72 #else /* !__DARWIN8__ */
73 #define atomic_add(v, a)                hw_atomic_add((__u32 *)&((a)->counter), v)
74 #define atomic_sub(v, a)                hw_atomic_sub((__u32 *)&((a)->counter), v)
75 #define atomic_inc(a)                   atomic_add(1, a)
76 #define atomic_dec(a)                   atomic_sub(1, a)
77 #endif /* !__DARWIN8__ */
78 #define atomic_sub_and_test(v, a)       (atomic_sub(v, a) == (v))
79 #define atomic_dec_and_test(a)          (atomic_dec(a) == 1)
80 #define atomic_inc_return(a)            (atomic_inc(a) + 1)
81 #define atomic_dec_return(a)            (atomic_dec(a) - 1)
82
83 #include <libsa/mach/mach.h>
84 typedef off_t                           loff_t;
85
86 #else   /* !__KERNEL__ */
87
88 #include <stdint.h>
89
90 typedef off_t                           loff_t;
91
92 #endif  /* __KERNEL END */
93 typedef unsigned short                  umode_t;
94
95 #endif  /* __XNU_CFS_TYPES_H__ */