diff options
author | rodrigc <rodrigc@FreeBSD.org> | 2005-12-12 01:04:32 +0000 |
---|---|---|
committer | rodrigc <rodrigc@FreeBSD.org> | 2005-12-12 01:04:32 +0000 |
commit | 410e08d350a2cfcb50386dc6b5a24a5d82825067 (patch) | |
tree | 8ac52e2fe37d3790aa9ac8fc061d5c395bc1b946 /sys/gnu/fs/xfs/FreeBSD/support/atomic.h | |
parent | ff6c302a67bb107dfea59fdc76583af9913df36e (diff) | |
download | FreeBSD-src-410e08d350a2cfcb50386dc6b5a24a5d82825067.zip FreeBSD-src-410e08d350a2cfcb50386dc6b5a24a5d82825067.tar.gz |
Initial import of read-only support for SGI's XFS filesystem.
Contributed by: XFS for FreeBSD project
Diffstat (limited to 'sys/gnu/fs/xfs/FreeBSD/support/atomic.h')
-rw-r--r-- | sys/gnu/fs/xfs/FreeBSD/support/atomic.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/sys/gnu/fs/xfs/FreeBSD/support/atomic.h b/sys/gnu/fs/xfs/FreeBSD/support/atomic.h new file mode 100644 index 0000000..f8b6c91 --- /dev/null +++ b/sys/gnu/fs/xfs/FreeBSD/support/atomic.h @@ -0,0 +1,37 @@ +#ifndef __XFS_SUPPORT_ATOMIC_H__ + +#include <sys/types.h> +#include <machine/atomic.h> + +typedef struct { + volatile unsigned int val; +} atomic_t; + +#define atomic_read(v) ((v)->val) +#define atomic_set(v, i) ((v)->val = (i)) + +#define atomic_add(i, v) atomic_add_int(&(v)->val, (i)) +#define atomic_inc(v) atomic_add_int(&(v)->val, 1) +#define atomic_dec(v) atomic_subtract_int(&(v)->val, 1) +#define atomic_sub(i, v) atomic_subtract_int(&(v)->val, (i)) +#define atomic_sub_and_test(i, v) (atomic_fetchadd_int(&(v)->val, (-i) == i) +#define atomic_dec_and_test(v) (atomic_fetchadd_int(&(v)->val, -1) == 1) + +/* + * This is used for two variables in XFS, one of which is a debug trace + * buffer index. + */ + +static __inline__ int atomicIncWithWrap(volatile unsigned int *ip, int val) +{ + unsigned int oldval, newval; + + do { + oldval = *ip; + newval = (oldval + 1 >= val) ? 0 : oldval + 1; + } while (atomic_cmpset_rel_int(ip, oldval, newval) == 0); + + return oldval; +} + +#endif /* __XFS_SUPPORT_ATOMIC_H__ */ |