generic___test_and_set_bit(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… generic___test_and_set_bit β€” from the Kernel API Manual, bestie ✨

Okay so picture this: you're deep in the kernel tree, you open up generic___test_and_set_bit from the Kernel API Manual, and you're like "what does this even do" β€” don't worry, I got you.


🌸 NAME 🌸

generic___test_and_set_bit β€” set a bit and return its old value, like a glow-up for one single bit πŸ‘‘


✨ SYNOPSIS ✨

bool generic___test_and_set_bit (unsigned long nr , volatile unsigned long *addr );

πŸŽ€ ARGUMENTS πŸŽ€

  • nr β€” the bit you wanna set 🎯 literally just the bit number, that's it
  • addr β€” the address to count from πŸ“

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea, and it's kind of a big deal: this operation is non-atomic and it can be reordered 😭 like, it's not out here protecting you.

And the part that lowkey hurts? If two of these race each other, one can appear to succeed but actually fail πŸ’€ yes, fr fr, it lied to your face.

🚨 So you must protect multiple accesses with a lock. Not optional. Not a vibe suggestion. Get the lock, bestie πŸ”’

πŸ’œ SEE ALSO πŸ’œ


🫢 okay that's the whole page! This one lives at ./include/asm-generic/bitops, dated October 2026, and it's generic___test_and_set_bit(9) β€” go forth and lock your accesses, mwah πŸ’‹πŸŽ€

πŸ“¦ where this page comes from