___test_and_clear_bit(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 ___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 🧚


🌈 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