Deleted Added
full compact
atomic.h (314210) atomic.h (315371)
1/*-
2 * Copyright (c) 1998 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1998 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: stable/11/sys/i386/include/atomic.h 314210 2017-02-24 16:02:01Z kib $
26 * $FreeBSD: stable/11/sys/i386/include/atomic.h 315371 2017-03-16 06:00:27Z mjg $
27 */
28#ifndef _MACHINE_ATOMIC_H_
29#define _MACHINE_ATOMIC_H_
30
31#ifndef _SYS_CDEFS_H_
32#error this file needs sys/cdefs.h as a prerequisite
33#endif
34

--- 66 unchanged lines hidden (view full) ---

101 * This allows kernel modules to be portable between UP and SMP systems.
102 */
103#if defined(KLD_MODULE) || !defined(__GNUCLIKE_ASM)
104#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \
105void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v); \
106void atomic_##NAME##_barr_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
107
108int atomic_cmpset_int(volatile u_int *dst, u_int expect, u_int src);
27 */
28#ifndef _MACHINE_ATOMIC_H_
29#define _MACHINE_ATOMIC_H_
30
31#ifndef _SYS_CDEFS_H_
32#error this file needs sys/cdefs.h as a prerequisite
33#endif
34

--- 66 unchanged lines hidden (view full) ---

101 * This allows kernel modules to be portable between UP and SMP systems.
102 */
103#if defined(KLD_MODULE) || !defined(__GNUCLIKE_ASM)
104#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \
105void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v); \
106void atomic_##NAME##_barr_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
107
108int atomic_cmpset_int(volatile u_int *dst, u_int expect, u_int src);
109int atomic_fcmpset_int(volatile u_int *dst, u_int *expect, u_int src);
109u_int atomic_fetchadd_int(volatile u_int *p, u_int v);
110int atomic_testandset_int(volatile u_int *p, u_int v);
111int atomic_testandclear_int(volatile u_int *p, u_int v);
112void atomic_thread_fence_acq(void);
113void atomic_thread_fence_acq_rel(void);
114void atomic_thread_fence_rel(void);
115void atomic_thread_fence_seq_cst(void);
116

--- 65 unchanged lines hidden (view full) ---

182 : "=q" (res), /* 0 */
183 "+m" (*dst), /* 1 */
184 "+a" (expect) /* 2 */
185 : "r" (src) /* 3 */
186 : "memory", "cc");
187 return (res);
188}
189
110u_int atomic_fetchadd_int(volatile u_int *p, u_int v);
111int atomic_testandset_int(volatile u_int *p, u_int v);
112int atomic_testandclear_int(volatile u_int *p, u_int v);
113void atomic_thread_fence_acq(void);
114void atomic_thread_fence_acq_rel(void);
115void atomic_thread_fence_rel(void);
116void atomic_thread_fence_seq_cst(void);
117

--- 65 unchanged lines hidden (view full) ---

183 : "=q" (res), /* 0 */
184 "+m" (*dst), /* 1 */
185 "+a" (expect) /* 2 */
186 : "r" (src) /* 3 */
187 : "memory", "cc");
188 return (res);
189}
190
191static __inline int
192atomic_fcmpset_int(volatile u_int *dst, u_int *expect, u_int src)
193{
194 u_char res;
195
196 __asm __volatile(
197 " " MPLOCKED " "
198 " cmpxchgl %3,%1 ; "
199 " sete %0 ; "
200 "# atomic_cmpset_int"
201 : "=q" (res), /* 0 */
202 "+m" (*dst), /* 1 */
203 "+a" (*expect) /* 2 */
204 : "r" (src) /* 3 */
205 : "memory", "cc");
206 return (res);
207}
208
190/*
191 * Atomically add the value of v to the integer pointed to by p and return
192 * the previous value of *p.
193 */
194static __inline u_int
195atomic_fetchadd_int(volatile u_int *p, u_int v)
196{
197

--- 452 unchanged lines hidden (view full) ---

650#define atomic_clear_acq_int atomic_clear_barr_int
651#define atomic_clear_rel_int atomic_clear_barr_int
652#define atomic_add_acq_int atomic_add_barr_int
653#define atomic_add_rel_int atomic_add_barr_int
654#define atomic_subtract_acq_int atomic_subtract_barr_int
655#define atomic_subtract_rel_int atomic_subtract_barr_int
656#define atomic_cmpset_acq_int atomic_cmpset_int
657#define atomic_cmpset_rel_int atomic_cmpset_int
209/*
210 * Atomically add the value of v to the integer pointed to by p and return
211 * the previous value of *p.
212 */
213static __inline u_int
214atomic_fetchadd_int(volatile u_int *p, u_int v)
215{
216

--- 452 unchanged lines hidden (view full) ---

669#define atomic_clear_acq_int atomic_clear_barr_int
670#define atomic_clear_rel_int atomic_clear_barr_int
671#define atomic_add_acq_int atomic_add_barr_int
672#define atomic_add_rel_int atomic_add_barr_int
673#define atomic_subtract_acq_int atomic_subtract_barr_int
674#define atomic_subtract_rel_int atomic_subtract_barr_int
675#define atomic_cmpset_acq_int atomic_cmpset_int
676#define atomic_cmpset_rel_int atomic_cmpset_int
677#define atomic_fcmpset_acq_int atomic_fcmpset_int
678#define atomic_fcmpset_rel_int atomic_fcmpset_int
658
659#define atomic_set_acq_long atomic_set_barr_long
660#define atomic_set_rel_long atomic_set_barr_long
661#define atomic_clear_acq_long atomic_clear_barr_long
662#define atomic_clear_rel_long atomic_clear_barr_long
663#define atomic_add_acq_long atomic_add_barr_long
664#define atomic_add_rel_long atomic_add_barr_long
665#define atomic_subtract_acq_long atomic_subtract_barr_long
666#define atomic_subtract_rel_long atomic_subtract_barr_long
667#define atomic_cmpset_acq_long atomic_cmpset_long
668#define atomic_cmpset_rel_long atomic_cmpset_long
679
680#define atomic_set_acq_long atomic_set_barr_long
681#define atomic_set_rel_long atomic_set_barr_long
682#define atomic_clear_acq_long atomic_clear_barr_long
683#define atomic_clear_rel_long atomic_clear_barr_long
684#define atomic_add_acq_long atomic_add_barr_long
685#define atomic_add_rel_long atomic_add_barr_long
686#define atomic_subtract_acq_long atomic_subtract_barr_long
687#define atomic_subtract_rel_long atomic_subtract_barr_long
688#define atomic_cmpset_acq_long atomic_cmpset_long
689#define atomic_cmpset_rel_long atomic_cmpset_long
690#define atomic_fcmpset_acq_long atomic_fcmpset_long
691#define atomic_fcmpset_rel_long atomic_fcmpset_long
669
670#define atomic_readandclear_int(p) atomic_swap_int(p, 0)
671#define atomic_readandclear_long(p) atomic_swap_long(p, 0)
672
673/* Operations on 8-bit bytes. */
674#define atomic_set_8 atomic_set_char
675#define atomic_set_acq_8 atomic_set_acq_char
676#define atomic_set_rel_8 atomic_set_rel_char

--- 38 unchanged lines hidden (view full) ---

715#define atomic_subtract_32 atomic_subtract_int
716#define atomic_subtract_acq_32 atomic_subtract_acq_int
717#define atomic_subtract_rel_32 atomic_subtract_rel_int
718#define atomic_load_acq_32 atomic_load_acq_int
719#define atomic_store_rel_32 atomic_store_rel_int
720#define atomic_cmpset_32 atomic_cmpset_int
721#define atomic_cmpset_acq_32 atomic_cmpset_acq_int
722#define atomic_cmpset_rel_32 atomic_cmpset_rel_int
692
693#define atomic_readandclear_int(p) atomic_swap_int(p, 0)
694#define atomic_readandclear_long(p) atomic_swap_long(p, 0)
695
696/* Operations on 8-bit bytes. */
697#define atomic_set_8 atomic_set_char
698#define atomic_set_acq_8 atomic_set_acq_char
699#define atomic_set_rel_8 atomic_set_rel_char

--- 38 unchanged lines hidden (view full) ---

738#define atomic_subtract_32 atomic_subtract_int
739#define atomic_subtract_acq_32 atomic_subtract_acq_int
740#define atomic_subtract_rel_32 atomic_subtract_rel_int
741#define atomic_load_acq_32 atomic_load_acq_int
742#define atomic_store_rel_32 atomic_store_rel_int
743#define atomic_cmpset_32 atomic_cmpset_int
744#define atomic_cmpset_acq_32 atomic_cmpset_acq_int
745#define atomic_cmpset_rel_32 atomic_cmpset_rel_int
746#define atomic_fcmpset_32 atomic_fcmpset_int
747#define atomic_fcmpset_acq_32 atomic_fcmpset_acq_int
748#define atomic_fcmpset_rel_32 atomic_fcmpset_rel_int
723#define atomic_swap_32 atomic_swap_int
724#define atomic_readandclear_32 atomic_readandclear_int
725#define atomic_fetchadd_32 atomic_fetchadd_int
726#define atomic_testandset_32 atomic_testandset_int
727#define atomic_testandclear_32 atomic_testandclear_int
728
729/* Operations on pointers. */
730#define atomic_set_ptr(p, v) \

--- 27 unchanged lines hidden (view full) ---

758#define atomic_cmpset_ptr(dst, old, new) \
759 atomic_cmpset_int((volatile u_int *)(dst), (u_int)(old), (u_int)(new))
760#define atomic_cmpset_acq_ptr(dst, old, new) \
761 atomic_cmpset_acq_int((volatile u_int *)(dst), (u_int)(old), \
762 (u_int)(new))
763#define atomic_cmpset_rel_ptr(dst, old, new) \
764 atomic_cmpset_rel_int((volatile u_int *)(dst), (u_int)(old), \
765 (u_int)(new))
749#define atomic_swap_32 atomic_swap_int
750#define atomic_readandclear_32 atomic_readandclear_int
751#define atomic_fetchadd_32 atomic_fetchadd_int
752#define atomic_testandset_32 atomic_testandset_int
753#define atomic_testandclear_32 atomic_testandclear_int
754
755/* Operations on pointers. */
756#define atomic_set_ptr(p, v) \

--- 27 unchanged lines hidden (view full) ---

784#define atomic_cmpset_ptr(dst, old, new) \
785 atomic_cmpset_int((volatile u_int *)(dst), (u_int)(old), (u_int)(new))
786#define atomic_cmpset_acq_ptr(dst, old, new) \
787 atomic_cmpset_acq_int((volatile u_int *)(dst), (u_int)(old), \
788 (u_int)(new))
789#define atomic_cmpset_rel_ptr(dst, old, new) \
790 atomic_cmpset_rel_int((volatile u_int *)(dst), (u_int)(old), \
791 (u_int)(new))
792#define atomic_fcmpset_ptr(dst, old, new) \
793 atomic_fcmpset_int((volatile u_int *)(dst), (u_int *)(old), (u_int)(new))
794#define atomic_fcmpset_acq_ptr(dst, old, new) \
795 atomic_fcmpset_acq_int((volatile u_int *)(dst), (u_int *)(old), \
796 (u_int)(new))
797#define atomic_fcmpset_rel_ptr(dst, old, new) \
798 atomic_fcmpset_rel_int((volatile u_int *)(dst), (u_int *)(old), \
799 (u_int)(new))
766#define atomic_swap_ptr(p, v) \
767 atomic_swap_int((volatile u_int *)(p), (u_int)(v))
768#define atomic_readandclear_ptr(p) \
769 atomic_readandclear_int((volatile u_int *)(p))
770
771#endif /* !WANT_FUNCTIONS */
772
773#if defined(_KERNEL)
774#define mb() __mbk()
775#define wmb() __mbk()
776#define rmb() __mbk()
777#else
778#define mb() __mbu()
779#define wmb() __mbu()
780#define rmb() __mbu()
781#endif
782
783#endif /* !_MACHINE_ATOMIC_H_ */
800#define atomic_swap_ptr(p, v) \
801 atomic_swap_int((volatile u_int *)(p), (u_int)(v))
802#define atomic_readandclear_ptr(p) \
803 atomic_readandclear_int((volatile u_int *)(p))
804
805#endif /* !WANT_FUNCTIONS */
806
807#if defined(_KERNEL)
808#define mb() __mbk()
809#define wmb() __mbk()
810#define rmb() __mbk()
811#else
812#define mb() __mbu()
813#define wmb() __mbu()
814#define rmb() __mbu()
815#endif
816
817#endif /* !_MACHINE_ATOMIC_H_ */