]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/gnu/fs/xfs/FreeBSD/support/atomic.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / gnu / fs / xfs / FreeBSD / support / atomic.h
1 #ifndef __XFS_SUPPORT_ATOMIC_H__
2
3 #include <sys/types.h>
4 #include <machine/atomic.h>
5
6 typedef struct {
7         volatile unsigned int   val;
8 } atomic_t;
9
10 #define atomic_read(v)                  ((v)->val)
11 #define atomic_set(v, i)                ((v)->val = (i))
12
13 #define atomic_add(i, v)                atomic_add_int(&(v)->val, (i))
14 #define atomic_inc(v)                   atomic_add_int(&(v)->val, 1)
15 #define atomic_dec(v)                   atomic_subtract_int(&(v)->val, 1)
16 #define atomic_sub(i, v)                atomic_subtract_int(&(v)->val, (i))
17 #define atomic_dec_and_test(v)          (atomic_fetchadd_int(&(v)->val, -1) == 1)
18
19 /*
20  * This is used for two variables in XFS, one of which is a debug trace
21  * buffer index.
22  */
23
24 static __inline__ int atomicIncWithWrap(volatile unsigned int *ip, int val)
25 {
26         unsigned int oldval, newval;
27
28         do {
29                 oldval = *ip;
30                 newval = (oldval + 1 >= val) ? 0 : oldval + 1;
31         } while (atomic_cmpset_rel_int(ip, oldval, newval) == 0);
32
33         return oldval;
34 }
35
36 #endif /* __XFS_SUPPORT_ATOMIC_H__ */