A81 Manipulation of Bit Chains

Although some of the functions needed for bit manipulation are implemented in C, the kernel prefers optimized assembler functions that are able to exploit the special features of the individual processors. Because some operations are atomic, they cannot be implemented in assembler code. The architecture-specific parts of the kernel must define the following functions in <asm-arch/bitops.h>:

□ void set_bit(int nr, volatile unsigned long * addr) sets the bit at position nr; counting begins at addr.

□ int test_bit(int nr, const volatile unsigned long * addr) checks whether the specified bit is set.

□ void clear_bit(int nr, volatile unsigned long * addr) deletes the bit at position nr (counting begins at addr).

□ void change_bit(int nr, volatile unsigned long * addr) reverses the bit value at position nr (counting begins at addr); in other words, a set bit is unset and vice versa.

□ int test_and_set_bit(int nr, volatile unsigned long * addr) sets a bit and returns its former value.

□ int test_and_clear_bit(int nr, volatile unsigned long * addr) deletes a bit and returns its former value.

□ int test_and_change_bit(int nr, volatile unsigned long* addr) reverses a bit value and returns its former value.

All of these functions are executed atomically, because lock statements are integrated in the assembler code. There are also non-atomic versions of these functions, which are prefixed with a double underscore (for example,_set_bit).

Continue reading here: A82 Conversion between Byte Orders

Was this article helpful?

0 0