raw_atomic_fetch_and(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… raw_atomic_fetch_and (9) β€” Kernel API Manual, bestie edition πŸŽ€

okay so listen. you know how sometimes you gotta do a bitwise AND but like… atomically? like nobody else gets to sneak in and touch the value while you're mid-operation? yeah. that's this. this is raw_atomic_fetch_and, and she is that girl. the Kernel API Manual could never explain it with this much flavor, so here we go πŸ’–


✨ SYNOPSIS ✨

int raw_atomic_fetch_and (int i , atomic_t *v );

literally the whole signature. iconic. no notes. 🫢


🌸 ARGUMENTS 🌸

  • i β€” an int value. this is the thing you're AND-ing with. the bit-mask bestie, if you will. πŸ’…
  • v β€” a pointer to an atomic_t. this is the main character. the value getting updated. she's living her life, and you're about to change it (atomically, obviously). ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so what it DOES is: it atomically updates v to (v & i) β€” and it does it with full ordering, which is the fancy way of saying it's not gonna get reordered on you, no cap. the whole operation is atomic. it's giving "you can't sit with us" energy to every other thread. πŸ”₯

also, and this is the part where you screenshot the group chat: it's safe to use in noinstr code (iykyk, that's the super-strict no-instrumentation zone). but everywhere else β€” like, the normal places β€” prefer atomic_fetch_and. don't be weird about it. πŸ™ˆ

ngl this distinction matters, bestie. noinstr code is a whole vibe with rules, and this function is the one that actually respects them. use it there, and use the regular one everywhere else.

⭐ RETURN ⭐

the original value of v β€” like, the value from before the AND happened. so you get the receipts of what it used to be. the fetch in fetch_and is not lying to you. πŸ’€βœ¨


πŸ‘‘ SEE ALSO πŸ‘‘

the whole atomic cinematic universe, in the exact order the manpage handed it to us. no skips, no shuffles, we're doing the full discography πŸŽ§πŸ’œ

and first, the kernel file:

  • ./include/linux/atomic/atomic-arch-fallback.h

then the 32-bit girlies:

and then the 64-bit girlies, because they deserve their own moment:


and that's the whole page, bestie, you ate that πŸ’…βœ¨

cute lil sign-off: this one came from ./include/linux/atomic in the Kernel API Manual, dated October 2026, and she's filed under raw_atomic_fetch_and(9) β€” mwah, go forth and AND atomically πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from