Linux kernel driver bit operations

Source: Internet
Author: User
The bitwise operation of the Linux kernel driver atomic_t is good in integer arithmetic. However, it cannot work well when you need to perform an atomic operation on a single bit. Therefore, the kernel provides a set of functions to modify or test a single bit atomically. Because the entire operation is in the single... Info & nbs Linux kernel driver bit operation atomic_t type is good in integer arithmetic. However, it cannot work well when you need to perform an atomic operation on a single bit. Therefore, the kernel provides a set of functions to modify or test a single bit atomically. Because the entire operation occurs in a single step, no interruption (or other processors) can interfere. Www.2cto.com atomic bit operations are very fast, because they use a single machine command for operations, and at any time the low-layer platform does not need to prohibit interruption. The function is system dependent and declared in. They are atomic, even on SMP computers, and are useful for cross-processor consistency. Unfortunately, data in these functions is also dependent on the system. The nr parameter (indicating which bit to operate) is often defined as int, but in several systems it is unsigned long. the address to be modified is often an unsigned long pointer, but several systems use void * instead. Various bit operations are: void set_bit (nr, void * addr); set the nr bit in the data item pointed to by addr. Void clear_bit (nr, void * addr); clears the unsigned long data located at the addr. Its semantics is opposite to that of set_bit. Void change_bit (nr, void * addr); flip this bit. Test_bit (nr, void * addr); this function is the only bit operation that does not need to be atomic; it simply returns the current value of this bit. Int test_and_set_bit (nr, void * addr); int test_and_clear_bit (nr, void * addr); int test_and_change_bit (nr, void * addr); the atomic action is as listed above, besides, they also return the previous values of this bit.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.