Skip to content

Commit

Permalink
[PARISC] Only write to memory in test_and_set_bit/test_and_clear_bit …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
Matthew Wilcox authored and Kyle McMartin committed Feb 17, 2007
1 parent d6ce862 commit af5917f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions include/asm-parisc/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit af5917f

Please sign in to comment.