xref: /haiku/src/libs/compat/freebsd_network/compat/machine/atomic.h (revision 5cad57c43b0225be334092e4700b79392db86f2d)
1 /*
2  * Copyright 2007, Hugo Santos. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _FBSD_COMPAT_MACHINE_ATOMIC_H_
6 #define _FBSD_COMPAT_MACHINE_ATOMIC_H_
7 
8 
9 #include <KernelExport.h>
10 
11 
12 #define atomic_add_int(ptr, value) \
13 	atomic_add((int32 *)(ptr), value)
14 
15 #define atomic_subtract_int(ptr, value) \
16 	atomic_add((int32 *)(ptr), -value)
17 
18 #define atomic_load_int(ptr) \
19 	atomic_get((int32 *)ptr)
20 
21 #define atomic_set_acq_32(ptr, value) \
22 	atomic_set_int(ptr, value)
23 
24 #define atomic_set_int(ptr, value) \
25 	atomic_or((int32 *)(ptr), value)
26 
27 #define atomic_readandclear_int(ptr) \
28 	atomic_set((int32 *)(ptr), 0)
29 
30 #define atomic_cmpset_int(ptr, old, new) \
31 	(atomic_test_and_set((int32 *)(ptr), new, old) == (int32)old)
32 
33 #define atomic_add_32			atomic_add_int
34 #define atomic_subtract_32		atomic_subtract_int
35 #define atomic_load_acq_32		atomic_load_int
36 #define atomic_store_rel_int	atomic_set_acq_32
37 #define atomic_cmpset_acq_int	atomic_cmpset_int
38 
39 #define	atomic_load_32(ptr)		(*(volatile uint32 *)(ptr))
40 #define atomic_set_32(ptr, val)	atomic_set((int32 *)ptr, val)
41 #define atomic_fetchadd_32(ptr, val)	atomic_add((int32 *)ptr, val)
42 
43 #define mb()    memory_full_barrier()
44 #define wmb()   memory_write_barrier_inline()
45 #define rmb()   memory_read_barrier()
46 
47 #endif	/* _FBSD_COMPAT_MACHINE_ATOMIC_H_ */
48