ATOMIC_ADD_INT(9)
β¨ ATOMIC_ADD_INT β¨
okay so bestie, welcome to the ATOMIC_ADD_INT page β it's from the Kernel Developer's Manual and honestly it's giving "small but mighty" π
. Four functions, one job: adding numbers in a way that literally no one can mess up, not even other CPUs or interrupts. let's get into it π«Ά
πΈ NAME πΈ
atomic_add_int, atomic_add_int_nv, atomic_add_long, atomic_add_long_nv β atomic addition operations β¨
likeβ¦ addition, but the safest addition you've ever seen. π
π¦ SYNOPSIS π¦
#include <sys/atomic.h>
void
atomic_add_int(volatile unsigned int *p, unsigned int v);
unsigned int
atomic_add_int_nv(volatile unsigned int *p, unsigned int v);
void
atomic_add_long(volatile unsigned long *p, unsigned long v);
unsigned long
atomic_add_long_nv(volatile unsigned long *p, unsigned long v);
yes the includes go exactly like that, don't come for me π
π DESCRIPTION π
the atomic_add squad provides an interface for atomically performing add operations and add-and-fetch operations β atomically with respect to interrupts and multiple processors in the system. so no matter how chaotic the vibes get on your machine, this add is gonna slay in one clean, uninterruptible step π₯
the value referenced by the pointer p gets incremented by the value v. that's it. that's the whole lore. β¨
π§ CONTEXT π§
okay so where can you call these? literally everywhere, bestie:
atomic_add_int(), atomic_add_int_nv(), atomic_add_long(), and atomic_add_long_nv() can all be called during autoconf, from process context, or from interrupt context. all four, all three places. main character energy across the whole kernel π
β RETURN VALUES β
atomic_add_intandatomic_add_longβ do the addition and give you nothing back. no knowledge of the value atp. silent. mysterious. πatomic_add_int_nvandatomic_add_long_nvβ do the addition and hand you the value atpafter the addition was performed. the "nv" girlies ate and left no crumbs π
π SEE ALSO π
go read those too, iykyk π
π HISTORY π
The atomic_add functions first appeared in NetBSD 5.0 and OpenBSD 5.5. iconic behavior from both, fr fr π¦
ngl there's no warnings or bugs section in this one β it's just four little functions doing their thing flawlessly. periodt. π β¨
Debian β February 13, 2014 π
that's the whole page, bestie! this vibe check was brought to you by the ATOMIC_ADD_INT(9) manual page, dated February 13, 2014, straight from Debian's kernel developer docs. now go add some integers, atomically, and stay hydrated ππ§β¨
π¦ 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