[parisc-linux-cvs] __test_and_change_bit()

Paul Bame bame@fc.hp.com
Thu, 05 Jul 2001 21:32:10 -0600


just like test_and_change_bit() without the locking

Index: bitops.h
===================================================================
RCS file: /home/cvs/parisc/linux/include/asm-parisc/bitops.h,v
retrieving revision 1.12
diff -u -r1.12 bitops.h
--- bitops.h	2001/07/06 02:11:41	1.12
+++ bitops.h	2001/07/06 03:31:06
@@ -77,15 +77,22 @@
 	return oldbit;
 }
 
-/**
- * __change_bit - Toggle a bit in memory
- * @nr: the bit to set
- * @addr: the address to start counting from
- *
- * Unlike change_bit(), this function is non-atomic and may be reordered.
- * If it's called on the same region of memory simultaneously, the effect
- * may be that only one operation succeeds.
- */
+static __inline__ int __test_and_change_bit(int nr, void * address)
+{
+	unsigned long mask;
+	unsigned long *addr = (unsigned long *) address;
+	int oldbit;
+
+	addr += (nr >> SHIFT_PER_LONG);
+
+	mask = 1L << CHOP_SHIFTCOUNT(nr);
+	oldbit = (*addr & mask) ? 1 : 0;
+	*addr ^= mask;
+
+	return oldbit;
+}
+
+/* see asm-i386/bitops.h */
 static __inline__ void __change_bit(int nr, void * address)
 {
 	unsigned long mask;