1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
21 * Basic library routines.
25 #ifndef __LIBCFS_DARWIN_XNU_TYPES_H__
26 #define __LIBCFS_DARWIN_XNU_TYPES_H__
28 #ifndef __LIBCFS_LIBCFS_H__
29 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
32 #include <mach/mach_types.h>
33 #include <sys/types.h>
35 #ifndef _BLKID_TYPES_H
36 #define _BLKID_TYPES_H
39 typedef u_int8_t __u8;
40 typedef u_int16_t __u16;
41 typedef u_int32_t __u32;
42 typedef u_int64_t __u64;
44 typedef int16_t __s16;
45 typedef int32_t __s32;
46 typedef int64_t __s64;
50 #include <kern/kern_types.h>
53 typedef struct { int e; } event_chan_t;
59 #include <libkern/OSAtomic.h>
61 typedef struct { volatile uint32_t counter; } atomic_t;
63 #define ATOMIC_INIT(i) { (i) }
64 #define atomic_read(a) ((a)->counter)
65 #define atomic_set(a, v) (((a)->counter) = (v))
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)
83 #include <libsa/mach/mach.h>
86 #else /* !__KERNEL__ */
92 #endif /* __KERNEL END */
93 typedef unsigned short umode_t;
95 #endif /* __XNU_CFS_TYPES_H__ */