Atomic bit operation

      The arguments to the operation function are a pointer and a tag

 

Atomic bit operations are defined in the file . It's strange that bit manipulation functions operate on ordinary memory addresses . Atomic bit operations are, in most cases, memory access to a word length , Therefore, the tag number should be located in 0-31 between ( stay 64 It's on a bit machine 0-63 between ), But there is no limit to the range of tags .

 

Some functions of bit operation in atomic operation are as follows :
void set_bit(int nr, void *addr)        Atomic settings addr Reference to nr position
void clear_bit(int nr, void *addr)      The first order of the object referred to by the atomic emptying nr position
void change_bit(nr, void *addr)         Atom flip addr Reference to nr position
int test_bit(nr, void *addr)            Return of atoms addr Bit referred object nr position
int test_and_set_bit(nr, void *addr)    Atomic settings addr Of the object referred to nr position , And return the original value
int test_and_clear_bit(nr, void *addr)  Atomic emptying addr Of the object referred to nr position , And return the original value
int test_and_change_bit(nr, void *addr)  Atom flip addr Of the object referred to nr position , And return the original value

 

    unsigned long word = 0;

    set_bit(0, &word); /* The first 0 Bit is set */

    set_bit(1, &word); /* The first 1 Bit is set */

    clear_bit(1, &word); /* The first 1 Bit cleared */

    change_bit(0, &word); /* Flip page 0 position */

 

 

Technology
©2019-2020 Toolsou All rights reserved,
Send love - A little romance for programmers VHDL—— Design of frequency divider Python Implementation of Hanoi Tower code It's over , Starting salary 30khtml+css+js Make a simple website home page QQ Login interface implementation Hill sorting of sorting algorithm ——c++ realization 【 Wechat applet learning 】 Netease music cloud code page implementation details Resume the 13th session python Blue Bridge Cup 2022 Solution to the 13th Blue Bridge Cup ( whole )