Re: set_bit() function.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 06, 2001 at 11:04:38AM -0700, Steven Liu wrote:

> extern __inline__ void set_bit(int nr, void * addr)
> {
> 	int	mask;
> 	int	*a = addr;
> 	__bi_flags;
> 
> 	a += nr >> 5;                        // <---- why shits right 5
> bits? 
> 	mask = 1 << (nr & 0x1f);
> 	__bi_save_flags(flags);
> 	__bi_cli();
> 	*a |= mask;
> 	__bi_restore_flags(flags);
> }
> 
> In
> 
> extern __inline__ int test_bit(int nr, const void *addr)
> {
> 	return ((1UL << (nr & 31)) & (((const unsigned int *) addr)[nr
> >> 5])) != 0;
> }
> 
> addr is always passed in as a pointer to an integer. Why does it use
> array [nr >>5]?

Linux bitfields can have an arbitrary size, more than a single machine
word.  Bitfields consist of a arrays of unsigned longs - note that this
makes a difference for 32-bit and 64-bit kernels!.

  Ralf


[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux