Atomic increment and get?

mdf at mdf at
Mon Oct 3 14:47:57 UTC 2011

2011/10/3 Lev Serebryakov <lev at>:
>  Is here atomic increment and get (or add and get) operation in
>  kernel? I cannot find one. Here is atomic_add_32(), but it doesn't
>  return result. And here is no atomic_add_64() on 32 bit system :(

See atomic_fetchadd_int.

Not all hardware has 64-bit atomic instructions available in 32-bit
mode so it's not machine-independent.  Generally, for this case (and
potentially for sub-32-bit atomic operations [1]) a lock is used.

[1] with masking and shifting 32-bit atomics can be used to set data
in an 8 or 16 bit variable; see a recent commit to sys/vm.


More information about the freebsd-hackers mailing list