[dpdk-dev] atomic operations
Stephen Hemminger
stephen at networkplumber.org
Mon Jul 5 18:20:20 CEST 2021
On Mon, 5 Jul 2021 08:33:21 +0000
Ruifeng Wang <Ruifeng.Wang at arm.com> wrote:
> >
> > > > One simple example: increment a counter atomically.
> > > > __atomic_fetch_add(&counter, 1, __ATOMIC_RELAXED); or
> > > > __atomic_add_fetch(&counter, 1, __ATOMIC_RELAXED);
> >
> > I really hate how atomics are "documented" in GCC doc.
> > For instance, it doesn't say what is returned (old or new value) in above
> > functions.
> >
> Returns are described as "the result of the operation" and "the value that had previously been in *ptr".
> It can be more concise.
Since English language parses left to right, the function name seem really obvious
to me. __atomic_fetch_add returns the result before the add, and __atomic_add_fetch returns
the result after the add. The one non-obvious question is which way is faster if the
result is not being used?
More information about the dev
mailing list