diff options
author | Matthew Wilcox <matthew@wil.cx> | 2006-12-14 09:00:25 -0700 |
---|---|---|
committer | Kyle McMartin <kyle@athena.road.mcmartin.ca> | 2007-02-17 00:43:03 -0500 |
commit | af5917f0cd60715ed09874bb793d4f62ba692f47 (patch) | |
tree | f808220b3254089658d1c35c76096aadf989f38b /include | |
parent | d6ce8626dbc7d277d29b62e31c24ce777c60546b (diff) |
[PARISC] Only write to memory in test_and_set_bit/test_and_clear_bit if we're
going to change the bit.
Signed-off-by: Matthew Wilcox <matthew@wil.cx>
Signed-off-by: Kyle McMartin <kyle@parisc-linux.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-parisc/bitops.h | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/include/asm-parisc/bitops.h b/include/asm-parisc/bitops.h index 900561922c4c..9577342f21aa 100644 --- a/include/asm-parisc/bitops.h +++ b/include/asm-parisc/bitops.h @@ -60,31 +60,37 @@ static __inline__ void change_bit(int nr, volatile unsigned long * addr) static __inline__ int test_and_set_bit(int nr, volatile unsigned long * addr) { unsigned long mask = 1UL << CHOP_SHIFTCOUNT(nr); - unsigned long oldbit; + unsigned long old; unsigned long flags; + int set; addr += (nr >> SHIFT_PER_LONG); _atomic_spin_lock_irqsave(addr, flags); - oldbit = *addr; - *addr = oldbit | mask; + old = *addr; + set = (old & mask) ? 1 : 0; + if (!set) + *addr = old | mask; _atomic_spin_unlock_irqrestore(addr, flags); - return (oldbit & mask) ? 1 : 0; + return set; } static __inline__ int test_and_clear_bit(int nr, volatile unsigned long * addr) { unsigned long mask = 1UL << CHOP_SHIFTCOUNT(nr); - unsigned long oldbit; + unsigned long old; unsigned long flags; + int set; addr += (nr >> SHIFT_PER_LONG); _atomic_spin_lock_irqsave(addr, flags); - oldbit = *addr; - *addr = oldbit & ~mask; + old = *addr; + set = (old & mask) ? 1 : 0; + if (set) + *addr = old & ~mask; _atomic_spin_unlock_irqrestore(addr, flags); - return (oldbit & mask) ? 1 : 0; + return set; } static __inline__ int test_and_change_bit(int nr, volatile unsigned long * addr) |