summaryrefslogtreecommitdiffstats
path: root/sys/amd64/include/atomic.h
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2009-10-06 23:48:28 +0000
committerattilio <attilio@FreeBSD.org>2009-10-06 23:48:28 +0000
commitd6f29069b6735fa01a2f684d5224bd939b5ef84f (patch)
tree14e6fc34044b5c990034c97d6da17fd00690610d /sys/amd64/include/atomic.h
parentfab15b104fd8b8032114bca20d5768c8af19156d (diff)
downloadFreeBSD-src-d6f29069b6735fa01a2f684d5224bd939b5ef84f.zip
FreeBSD-src-d6f29069b6735fa01a2f684d5224bd939b5ef84f.tar.gz
- All the functions in atomic.h needs to be in "physical" form (like
not defined through macros or similar) in order to be later compiled in the kernel and offer this way the support for modules (and compatibility among the UP case and SMP case). Fix this for the newly introduced atomic_cmpset_barr_* cases by defining and specifying a template. Note that the new DEFINE_CMPSET_GEN() template save more typing on amd64 than the current code. [1] - Fix the style for memory barriers on amd64. [1] Reported by: Paul B. Mahol <onemda at gmail dot com>
Diffstat (limited to 'sys/amd64/include/atomic.h')
-rw-r--r--sys/amd64/include/atomic.h75
1 files changed, 29 insertions, 46 deletions
diff --git a/sys/amd64/include/atomic.h b/sys/amd64/include/atomic.h
index 4c415de..7d7199c 100644
--- a/sys/amd64/include/atomic.h
+++ b/sys/amd64/include/atomic.h
@@ -32,9 +32,9 @@
#error this file needs sys/cdefs.h as a prerequisite
#endif
-#define mb() __asm__ __volatile__ ("mfence;": : :"memory")
-#define wmb() __asm__ __volatile__ ("sfence;": : :"memory")
-#define rmb() __asm__ __volatile__ ("lfence;": : :"memory")
+#define mb() __asm __volatile("mfence;" : : : "memory")
+#define wmb() __asm __volatile("sfence;" : : : "memory")
+#define rmb() __asm __volatile("lfence;" : : : "memory")
/*
* Various simple operations on memory, each of which is atomic in the
@@ -131,50 +131,33 @@ struct __hack
* Returns 0 on failure, non-zero on success
*/
-static __inline int
-atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src)
-{
- u_char res;
-
- __asm __volatile(
- " " MPLOCKED " "
- " cmpxchgl %2,%1 ; "
- " sete %0 ; "
- "1: "
- "# atomic_cmpset_int"
- : "=a" (res), /* 0 */
- "=m" (*dst) /* 1 */
- : "r" (src), /* 2 */
- "a" (exp), /* 3 */
- "m" (*dst) /* 4 */
- : "memory");
-
- return (res);
-}
-
-static __inline int
-atomic_cmpset_long(volatile u_long *dst, u_long exp, u_long src)
-{
- u_char res;
-
- __asm __volatile(
- " " MPLOCKED " "
- " cmpxchgq %2,%1 ; "
- " sete %0 ; "
- "1: "
- "# atomic_cmpset_long"
- : "=a" (res), /* 0 */
- "=m" (*dst) /* 1 */
- : "r" (src), /* 2 */
- "a" (exp), /* 3 */
- "m" (*dst) /* 4 */
- : "memory");
-
- return (res);
-}
+#define DEFINE_CMPSET_GEN(NAME, TYPE, OP) \
+static __inline int \
+atomic_cmpset_##NAME(volatile u_##TYPE *dst, u_##TYPE exp, u_##TYPE src)\
+{ \
+ u_char res; \
+ \
+ __asm __volatile( \
+ " " MPLOCKED " " \
+ " " OP " %2,%1 ; " \
+ " sete %0 ; " \
+ "1: " \
+ "# atomic_cmpset_##NAME" \
+ : "=a" (res), /* 0 */ \
+ "=m" (*dst) /* 1 */ \
+ : "r" (src), /* 2 */ \
+ "a" (exp), /* 3 */ \
+ "m" (*dst) /* 4 */ \
+ : "memory"); \
+ \
+ return (res); \
+} \
+struct __hack
-#define atomic_cmpset_barr_int atomic_cmpset_int
-#define atomic_cmpset_barr_long atomic_cmpset_long
+DEFINE_CMPSET_GEN(int, int, "cmpxchgl");
+DEFINE_CMPSET_GEN(long, long, "cmpxchgq");
+DEFINE_CMPSET_GEN(barr_int, int, "cmpxchgl");
+DEFINE_CMPSET_GEN(barr_long, long, "cmpxchgq");
/*
* Atomically add the value of v to the integer pointed to by p and return
OpenPOWER on IntegriCloud