Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Jan 2003 20:47:50 -0800 (PST)
From:      Juli Mallett <jmallett@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 24210 for review
Message-ID:  <200301260447.h0Q4loSc052793@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=24210

Change 24210 by jmallett@jmallett_dalek on 2003/01/25 20:47:23

	Add the readandclear functions for int/long.  Add some comments
	about the format of this file.

Affected files ...

.. //depot/projects/mips/sys/mips/include/atomic.h#6 edit

Differences ...

==== //depot/projects/mips/sys/mips/include/atomic.h#6 (text+ko) ====

@@ -27,6 +27,16 @@
 #ifndef	_MACHINE_ATOMIC_H_
 #define	_MACHINE_ATOMIC_H_
 
+/*
+ * Atomic operations on the MIPS, keep code abstracted up to the point
+ * that it is no longer clean.  Keep operations on each type sorted in
+ * an order relative to eachother.
+ */
+
+/*
+ * Integer atomic operations, hardware calls this single.
+ */
+
 #define	ATOMIC_OP(op, asmop)						\
 static __inline void							\
 atomic_ ## op ## _int(u_int *p, u_int val)				\
@@ -50,6 +60,30 @@
 ATOMIC_OP(set,		"or %[temp], %[temp], %[val]")
 ATOMIC_OP(subtract,	"subu %[temp], %[temp], %[val]")
 
+static __inline int
+atomic_readandclear_int(u_int *p)
+{
+	u_int temp, res;
+
+	__asm __volatile (
+	"1:\n\t"
+	"ll	%[temp], %[p]\n\t"
+	"move	%[res], %[temp]\n\t"
+	"move	%[temp], 0\n\t"
+	"sc	%[temp], %[p]\n\t"
+	"beqz	%[temp], 1b\n\t"
+	: [val] "=r"(val)
+	: [temp] "r"(temp), [p] "r"(p), [res] "r"(res)
+	: "memory"
+	);
+
+	return res;
+}
+
+/*
+ * Long atomic operations, hardware calls this double.
+ */
+
 #define	ATOMIC_DOP(op, asmop)						\
 static __inline void							\
 atomic_ ## op ## _long(u_long *p, u_long val)				\
@@ -73,4 +107,24 @@
 ATOMIC_DOP(set,		"or %[temp], %[temp], %[val]")
 ATOMIC_DOP(subtract,	"dsubu %[temp], %[temp], %[val]")
 
+static __inline long
+atomic_readandclear_int(u_long *p)
+{
+	u_long temp, res;
+
+	__asm __volatile (
+	"1:\n\t"
+	"lld	%[temp], %[p]\n\t"
+	"move	%[res], %[temp]\n\t"
+	"move	%[temp], 0\n\t"
+	"scd	%[temp], %[p]\n\t"
+	"beqz	%[temp], 1b\n\t"
+	: [val] "=r"(val)
+	: [temp] "r"(temp), [p] "r"(p), [res] "r"(res)
+	: "memory"
+	);
+
+	return res;
+}
+
 #endif /* !_MACHINE_ATOMIC_H_ */

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200301260447.h0Q4loSc052793>