generic___test_and_set_bit(9)
π 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 itaddrβ 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 π
- Kernel file
./include/asm-generic/bitops/generic-non-atomic.hπ generic___set_bit(9)generic___change_bit(9)generic___test_and_clear_bit(9)generic_test_bit(9)generic_test_bit_acquire(9)const_test_bit(9)
π«Ά 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
- 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