ATOMIC_DEC_INT(9)

πŸ“¦ in nixpkgs unstable

πŸ’… ATOMIC_DEC_INT(9) β€” the atomic decrement glow-up

okay bestie, welcome to section 9 of the Kernel Developer's Manual 🫢 this is ATOMIC_DEC_INT, and yes she's coming to you straight from the kernel-dev side of the house. buckle up, we're doing atomic decrements ✨


πŸŽ€ NAME πŸŽ€

atomic_dec_int, atomic_dec_int_nv, atomic_dec_long, atomic_dec_long_nv β€” atomic decrement operations. that's the whole vibe. four little functions, one very serious job πŸ”₯


✨ SYNOPSIS ✨

#include <sys/atomic.h>

void
atomic_dec_int(volatile unsigned int *p);

unsigned int
atomic_dec_int_nv(volatile unsigned int *p);

void
atomic_dec_long(volatile unsigned long *p);

unsigned long
atomic_dec_long_nv(volatile unsigned long *p);

look at her. iconic. the _nv girlies return a value, the others just do the thing and dip πŸ’… and yes, #include <sys/atomic.h> is mandatory, don't @ me.


🌸 DESCRIPTION 🌸

so the atomic_dec set of functions is this interface for atomically performing decrement and decrement-and-fetch operations β€” and by "atomically" we mean with respect to interrupts and multiple processors in the system. like, no cap, nobody can slide in mid-operation and mess with your number. main character energy only πŸ‘‘

the value referenced by the pointer p is decremented by 1. that's it. that's the whole lore. subtract one, but make it safe πŸ¦‹


🧚 CONTEXT 🧚

atomic_dec_int(), atomic_dec_int_nv(), atomic_dec_long(), and atomic_dec_long_nv() can all be called during autoconf, from process context, or from interrupt context.

all four. every single one. any of those three places. she's flexible like that πŸ’–


⭐ RETURN VALUES ⭐

  • atomic_dec_int and atomic_dec_long β€” perform the decrement without returning any knowledge of the value at p. they simply do the job and say nothing. mysterious. love that for them πŸ™ˆ
  • atomic_dec_int_nv and atomic_dec_long_nv β€” return the value at p after the decrement was performed. so you actually get the tea β˜• the _nv stands for something and she delivers.

πŸ¦‹ SEE ALSO πŸ¦‹

the whole friend group, fr fr. go say hi 🌈


πŸ’€ HISTORY πŸ’€

The atomic_add functions first appeared in NetBSD 5.0 and OpenBSD 5.5.

slight plot twist: yes, the HISTORY line says atomic_add even though this page is about atomic_dec. keeping it exactly as written because that's what the manpage says, and we do not rewrite history in this house 😭

and that's the page, bestie πŸ’œ this edition of the kernel manual was brought to you by Debian, dated February 13, 2014 β€” go forth and decrement responsibly, you absolute icon πŸŽ€βœ¨

πŸ“¦ 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