define first set of BIT* macros
define first set of BIT* macros - move BITOP_MASK and BITOP_WORD from asm-generic/bitops/atomic.h to include/linux/bitops.h and rename it to BIT_MASK and BIT_WORD - move BITS_TO_LONGS and BITS_PER_BYTE to bitops.h too and allow easily define another BITS_TO_something (e.g. in event.c) by BITS_TO_TYPE macro Remaining (and common) BIT macro will be defined after all occurences and conflicts will be sorted out in the patches. Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
5159f40742
commit
d05be13bcc
|
@ -3,9 +3,6 @@
|
||||||
|
|
||||||
#include <asm/types.h>
|
#include <asm/types.h>
|
||||||
|
|
||||||
#define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
|
|
||||||
#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
|
|
||||||
|
|
||||||
#ifdef CONFIG_SMP
|
#ifdef CONFIG_SMP
|
||||||
#include <asm/spinlock.h>
|
#include <asm/spinlock.h>
|
||||||
#include <asm/cache.h> /* we use L1_CACHE_BYTES */
|
#include <asm/cache.h> /* we use L1_CACHE_BYTES */
|
||||||
|
@ -66,8 +63,8 @@ extern raw_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned;
|
||||||
*/
|
*/
|
||||||
static inline void set_bit(int nr, volatile unsigned long *addr)
|
static inline void set_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
_atomic_spin_lock_irqsave(p, flags);
|
_atomic_spin_lock_irqsave(p, flags);
|
||||||
|
@ -87,8 +84,8 @@ static inline void set_bit(int nr, volatile unsigned long *addr)
|
||||||
*/
|
*/
|
||||||
static inline void clear_bit(int nr, volatile unsigned long *addr)
|
static inline void clear_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
_atomic_spin_lock_irqsave(p, flags);
|
_atomic_spin_lock_irqsave(p, flags);
|
||||||
|
@ -108,8 +105,8 @@ static inline void clear_bit(int nr, volatile unsigned long *addr)
|
||||||
*/
|
*/
|
||||||
static inline void change_bit(int nr, volatile unsigned long *addr)
|
static inline void change_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
_atomic_spin_lock_irqsave(p, flags);
|
_atomic_spin_lock_irqsave(p, flags);
|
||||||
|
@ -128,8 +125,8 @@ static inline void change_bit(int nr, volatile unsigned long *addr)
|
||||||
*/
|
*/
|
||||||
static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
|
static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
unsigned long old;
|
unsigned long old;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
|
@ -152,8 +149,8 @@ static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
|
||||||
*/
|
*/
|
||||||
static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
|
static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
unsigned long old;
|
unsigned long old;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
|
@ -175,8 +172,8 @@ static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
|
||||||
*/
|
*/
|
||||||
static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
|
static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
unsigned long old;
|
unsigned long old;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,6 @@
|
||||||
|
|
||||||
#include <asm/types.h>
|
#include <asm/types.h>
|
||||||
|
|
||||||
#define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
|
|
||||||
#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __set_bit - Set a bit in memory
|
* __set_bit - Set a bit in memory
|
||||||
* @nr: the bit to set
|
* @nr: the bit to set
|
||||||
|
@ -17,16 +14,16 @@
|
||||||
*/
|
*/
|
||||||
static inline void __set_bit(int nr, volatile unsigned long *addr)
|
static inline void __set_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
|
|
||||||
*p |= mask;
|
*p |= mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __clear_bit(int nr, volatile unsigned long *addr)
|
static inline void __clear_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
|
|
||||||
*p &= ~mask;
|
*p &= ~mask;
|
||||||
}
|
}
|
||||||
|
@ -42,8 +39,8 @@ static inline void __clear_bit(int nr, volatile unsigned long *addr)
|
||||||
*/
|
*/
|
||||||
static inline void __change_bit(int nr, volatile unsigned long *addr)
|
static inline void __change_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
|
|
||||||
*p ^= mask;
|
*p ^= mask;
|
||||||
}
|
}
|
||||||
|
@ -59,8 +56,8 @@ static inline void __change_bit(int nr, volatile unsigned long *addr)
|
||||||
*/
|
*/
|
||||||
static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
|
static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
unsigned long old = *p;
|
unsigned long old = *p;
|
||||||
|
|
||||||
*p = old | mask;
|
*p = old | mask;
|
||||||
|
@ -78,8 +75,8 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
|
||||||
*/
|
*/
|
||||||
static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
|
static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
unsigned long old = *p;
|
unsigned long old = *p;
|
||||||
|
|
||||||
*p = old & ~mask;
|
*p = old & ~mask;
|
||||||
|
@ -90,8 +87,8 @@ static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
|
||||||
static inline int __test_and_change_bit(int nr,
|
static inline int __test_and_change_bit(int nr,
|
||||||
volatile unsigned long *addr)
|
volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
unsigned long mask = BITOP_MASK(nr);
|
unsigned long mask = BIT_MASK(nr);
|
||||||
unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
|
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||||
unsigned long old = *p;
|
unsigned long old = *p;
|
||||||
|
|
||||||
*p = old ^ mask;
|
*p = old ^ mask;
|
||||||
|
@ -105,7 +102,7 @@ static inline int __test_and_change_bit(int nr,
|
||||||
*/
|
*/
|
||||||
static inline int test_bit(int nr, const volatile unsigned long *addr)
|
static inline int test_bit(int nr, const volatile unsigned long *addr)
|
||||||
{
|
{
|
||||||
return 1UL & (addr[BITOP_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
|
return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
|
#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
|
||||||
|
|
|
@ -2,6 +2,14 @@
|
||||||
#define _LINUX_BITOPS_H
|
#define _LINUX_BITOPS_H
|
||||||
#include <asm/types.h>
|
#include <asm/types.h>
|
||||||
|
|
||||||
|
#ifdef __KERNEL__
|
||||||
|
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
|
||||||
|
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
|
||||||
|
#define BITS_TO_TYPE(nr, t) (((nr)+(t)-1)/(t))
|
||||||
|
#define BITS_TO_LONGS(nr) BITS_TO_TYPE(nr, BITS_PER_LONG)
|
||||||
|
#define BITS_PER_BYTE 8
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Include this here because some architectures need generic_ffs/fls in
|
* Include this here because some architectures need generic_ffs/fls in
|
||||||
* scope
|
* scope
|
||||||
|
|
|
@ -3,12 +3,9 @@
|
||||||
|
|
||||||
#ifdef __KERNEL__
|
#ifdef __KERNEL__
|
||||||
|
|
||||||
#define BITS_TO_LONGS(bits) \
|
|
||||||
(((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
|
|
||||||
#define DECLARE_BITMAP(name,bits) \
|
#define DECLARE_BITMAP(name,bits) \
|
||||||
unsigned long name[BITS_TO_LONGS(bits)]
|
unsigned long name[BITS_TO_LONGS(bits)]
|
||||||
|
|
||||||
#define BITS_PER_BYTE 8
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <linux/posix_types.h>
|
#include <linux/posix_types.h>
|
||||||
|
|
Loading…
Reference in New Issue