ATOMIC_INC_INT(9)

πŸ“¦ in nixpkgs unstable

πŸ’… ATOMIC_INC_INT(9) β€” bestie's guide to atomic increments

okay so this is from the Kernel Developer's Manual, section 9, and it's literally the glow-up of "just add one" β€” but, like, safely. no cap.

✨ NAME ✨

atomic_inc_int, atomic_inc_int_nv, atomic_inc_long, atomic_inc_long_nv β€” the atomic increment operations. yes queen, all four of them, and they're a package deal.


πŸŽ€ SYNOPSIS πŸŽ€

first things first, you gotta pull in the header:

#include <sys/atomic.h>

then the whole squad, in order, exactly like this:

void
atomic_inc_int(volatile unsigned int *p);

unsigned int
atomic_inc_int_nv(volatile unsigned int *p);

void
atomic_inc_long(volatile unsigned long *p);

unsigned long
atomic_inc_long_nv(volatile unsigned long *p);

notice the _nv girlies return a value and the plain ones don't β€” that's the whole plot twist, more on that below 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so the atomic_inc fam gives you an interface for atomically doing increment operations and increment-and-fetch operations β€” atomically with respect to interrupts and multiple processors in the system. that last part is the whole point, iykyk. no sneaky race conditions, no two CPUs stepping on each other, it just works. slay.

the value referenced by the pointer p is incremented by 1. that's it. that's the job. one (1) singular unit of increase. iconic behaviour tbh ✨


🌸 CONTEXT 🌸

the good news bestie: atomic_inc_int(), atomic_inc_int_nv(), atomic_inc_long(), and atomic_inc_long_nv() can all be called during autoconf, from process context, or from interrupt context. all of them, every single one, no exceptions. flexible queens πŸ’…


πŸ‘‘ RETURN VALUES πŸ‘‘

  • atomic_inc_int and atomic_inc_long do the increment and return literally nothing β€” no knowledge of the value at p comes back to you. mysterious. withholding. main character energy πŸ™ˆ
  • atomic_inc_int_nv and atomic_inc_long_nv return the value at p after the increment was performed. so you get the receipts 🧾

πŸ’œ SEE ALSO πŸ’œ

go read these next, fr fr:


🌈 HISTORY 🌈

the atomic_inc functions first appeared in NetBSD 5.0 and OpenBSD 5.5. vintage but still relevant, we love a legacy icon ⭐


ngl, it's four tiny functions that add one to a number without breaking under concurrency. that's the whole vibe check. if you're touching shared values from interrupts or multiple processors, use these and not p++ like some kind of chaotic goblin πŸ’€

and that's the page, bestie! πŸŽ€ this lil doc came from Debian, dated February 13, 2014 β€” so it's giving throwback, but the atomic increment stays eternally fresh βœ¨πŸ’–πŸ¦‹

πŸ“¦ where this page comes from
  • nixpkgs unstable: cvs-export
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms