Whamcloud - gitweb
0fd2966c792bb970baee44977e7f1ef973ef4a80
[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 #define atomic_add(v, a)                OSAddAtomic(v, (SInt32 *)&((a)->counter))
68 #define atomic_sub(v, a)                OSAddAtomic(-(v), (SInt32 *)&((a)->counter))
69 #define atomic_inc(a)                   OSIncrementAtomic((SInt32 *)&((a)->counter))
70 #define atomic_dec(a)                   OSDecrementAtomic((SInt32 *)&((a)->counter))
71 #else /* !__DARWIN8__ */
72 #define atomic_add(v, a)                hw_atomic_add((uint32_t *)&((a)->counter), v)
73 #define atomic_sub(v, a)                hw_atomic_sub((uint32_t *)&((a)->counter), v)
74 #define atomic_inc(a)                   atomic_add(1, a)
75 #define atomic_dec(a)                   atomic_sub(1, a)
76 #endif /* !__DARWIN8__ */
77 #define atomic_sub_and_test(v, a)       ( atomic_sub(v, a) == -(a) )
78 #define atomic_dec_and_test(a)          ( atomic_dec(a) == 1 )
79
80 #include <libsa/mach/mach.h>
81 typedef off_t                           loff_t;
82
83 #else   /* !__KERNEL__ */
84
85 #include <stdint.h>
86
87 typedef off_t                           loff_t;
88
89 #endif  /* __KERNEL END */
90 typedef unsigned short                  umode_t;
91
92 #endif  /* __XNU_CFS_TYPES_H__ */