___test_and_clear_bit(9)
πΈ ___test_and_clear_bit β NAME π
okay so bestie, gather round: ___test_and_clear_bit is literally the function that clears a bit and returns its old value. that's the whole vibe. clear it, but tell me what it was first. iconic behaviour honestly π
it lives in the Kernel API Manual, which is a whole mood. and yes β count the underscores, there are three of them up front. do not come for me. π
β¨ SYNOPSIS β¨
bool ___test_and_clear_bit (unsigned long nr , volatile unsigned long
*addr );
so it hands you back a bool, takes a unsigned long nr, and a volatile unsigned long *addr. exactly like that. the spaces are part of the assignment, bestie, we don't touch them π«Ά
π¦ ARGUMENTS π¦
nrβ the bit to clear. the actual one. the chosen one. π―addrβ the address to count from. it's giving "start here and go find it" energy. π
π DESCRIPTION π
okay so this is the part where i need you to listen, because it's lowkey important:
this operation is non-atomic and can be reordered. no cap. it does not come with a seatbelt. π¨
and here's the spicy bit β if two examples of this operation race, one can appear to succeed but actually fail. appear. it's fake success. it's the "i sent the text" of kernel operations, ngl. π
so if you're doing multiple accesses, you must protect them with a lock. periodt. not optional, not a suggestion, not a "we'll fix it later" β a lock. π
bestie please. i am begging you. use a lock. i don't want to see your race condition on the timeline. π
π§ SEE ALSO π§
- kernel file:
./tools/include/asm-generic/bitops/non-atomic.hβ like, the lore document, go read it π ___set_bit(9)___change_bit(9)___test_and_set_bit(9)_test_bit(9)
π the cute sign-off π
this lil beauty came from ./tools/include/asm-generic/bi... (yes, it's abbreviated, that's just how the page do) and it's dated October 2026. so it's from the future, kind of. main character energy, honestly. βπ
slay, go clear your bits, and remember the lock. πβ¨
π¦ 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