test_and_set_bit(9)
π test_and_set_bit(9) β like, the Kernel API Manual page you actually wanna read
okay bestie, welcome to the Kernel API Manual, section 9, and today's main character is test_and_set_bit π
β¨ NAME β¨
test_and_set_bit β set a bit and return its old value. that's it, that's the whole vibe π
πΈ SYNOPSIS πΈ
bool test_and_set_bit (long nr , volatile unsigned long *addr );
literally just hand it a bit number and an address and it does the thing, no cap β¨
π¦ ARGUMENTS π¦
nrβ the bit you wanna set. which one? that one. the *nr*th one π―addrβ the address to count from. start counting here, bestie π«Ά
π₯ DESCRIPTION π₯
so this is an atomic fully-ordered operation β the docs literally say it comes with an implied full memory barrier. it's giving main character energy, it's giving "i don't need anyone to hold my hand" ππ
β οΈ okay but fr fr, "fully-ordered" is not a cute little detail, it's the whole point. don't go assuming you can reorder stuff around it.
π SEE ALSO π
- the kernel file itself:
./include/asm-generic/bitops/instrumented-atomic.hβ go read it, iykyk π set_bit(9)clear_bit(9)change_bit(9)test_and_clear_bit(9)test_and_change_bit(9)
the whole bit-twiddling friend group, honestly π
and that's the page!! π this one's from ./include/asm-generic/bitops, dated October 2026, and it's test_and_set_bit(9) forever and always β slay, go set some bits, mwah π§π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms