___test_and_set_bit(9)
π
___test_and_set_bit β Kernel API Manual, bestie edition π
okay so welcome to the Kernel API Manual, the little corner of the docs where we talk about bit-fiddling β¨ and today's main character is ___test_and_set_bit. yes it has three leading underscores. no we don't ask why. iykyk π
β¨ NAME β¨
___test_and_set_bit β set a bit and return its old value π«Ά
like, it flips the bit ON and hands you back what the bit used to be. that's the whole personality. iconic tbh π
πΈ SYNOPSIS πΈ
bool ___test_and_set_bit (unsigned long nr , volatile unsigned long
*addr );
literally copy that exactly, spacing and all, don't @ me π
π¦ ARGUMENTS π¦
nrβ the bit to set. which bit, bestie? this one. π―addrβ the address to count from. your starting point, your home base, your origin story π
π₯ DESCRIPTION π₯
okay so here's the tea and you need to hear it π΅
This operation is non-atomic and can be reordered. that's right, it's giving chaos gremlin energy π it does not respect your locks, it does not respect your ordering, it simply vibes β¨
and because of that: if two examples of this operation race, one can appear to succeed but actually fail. π not the fake success!! so rude.
β οΈ so what do you do? You must protect multiple accesses with a lock. fr fr. no cap. if you're touching this from more than one place, lock it down like it's your group chat π π
π SEE ALSO π
- Kernel file
./tools/include/asm-generic/bitops/non-atomic.hβ go read the source, bestie, it's all there π ___set_bit(9)___change_bit(9)___test_and_clear_bit(9)_test_bit(9)
(sibling energy, honestly. the whole bitops family ate π₯)
π okay that's the page!! this little masterpiece comes to you from ./tools/include/asm-generic/bi... (yes, truncated with dots, that's just how it's written, don't come for me π) and it's dated October 2026 β future icon behavior tbh β and it signs off as ___test_and_set_bit(9), three underscores and all, slay π
π
π¦ 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