Path: blob/master/include/asm-generic/bitops/non-atomic.h
10818 views
#ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_1#define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_23#include <asm/types.h>45/**6* __set_bit - Set a bit in memory7* @nr: the bit to set8* @addr: the address to start counting from9*10* Unlike set_bit(), this function is non-atomic and may be reordered.11* If it's called on the same region of memory simultaneously, the effect12* may be that only one operation succeeds.13*/14static inline void __set_bit(int nr, volatile unsigned long *addr)15{16unsigned long mask = BIT_MASK(nr);17unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);1819*p |= mask;20}2122static inline void __clear_bit(int nr, volatile unsigned long *addr)23{24unsigned long mask = BIT_MASK(nr);25unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);2627*p &= ~mask;28}2930/**31* __change_bit - Toggle a bit in memory32* @nr: the bit to change33* @addr: the address to start counting from34*35* Unlike change_bit(), this function is non-atomic and may be reordered.36* If it's called on the same region of memory simultaneously, the effect37* may be that only one operation succeeds.38*/39static inline void __change_bit(int nr, volatile unsigned long *addr)40{41unsigned long mask = BIT_MASK(nr);42unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);4344*p ^= mask;45}4647/**48* __test_and_set_bit - Set a bit and return its old value49* @nr: Bit to set50* @addr: Address to count from51*52* This operation is non-atomic and can be reordered.53* If two examples of this operation race, one can appear to succeed54* but actually fail. You must protect multiple accesses with a lock.55*/56static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)57{58unsigned long mask = BIT_MASK(nr);59unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);60unsigned long old = *p;6162*p = old | mask;63return (old & mask) != 0;64}6566/**67* __test_and_clear_bit - Clear a bit and return its old value68* @nr: Bit to clear69* @addr: Address to count from70*71* This operation is non-atomic and can be reordered.72* If two examples of this operation race, one can appear to succeed73* but actually fail. You must protect multiple accesses with a lock.74*/75static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)76{77unsigned long mask = BIT_MASK(nr);78unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);79unsigned long old = *p;8081*p = old & ~mask;82return (old & mask) != 0;83}8485/* WARNING: non atomic and it can be reordered! */86static inline int __test_and_change_bit(int nr,87volatile unsigned long *addr)88{89unsigned long mask = BIT_MASK(nr);90unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);91unsigned long old = *p;9293*p = old ^ mask;94return (old & mask) != 0;95}9697/**98* test_bit - Determine whether a bit is set99* @nr: bit number to test100* @addr: Address to start counting from101*/102static inline int test_bit(int nr, const volatile unsigned long *addr)103{104return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));105}106107#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */108109110