ATOMIC_DEC_INT(9)
π 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_intandatomic_dec_longβ perform the decrement without returning any knowledge of the value atp. they simply do the job and say nothing. mysterious. love that for them πatomic_dec_int_nvandatomic_dec_long_nvβ return the value atpafter the decrement was performed. so you actually get the tea β the_nvstands 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 saysatomic_addeven though this page is aboutatomic_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
- Copyright (c) 2014 David Gwynne <dlg@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms