[Issue 12891] add atomicInc and atomicDec to core.atomic
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Mar 30 13:56:55 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=12891
--- Comment #3 from Martin Nowak <code at dawg.eu> ---
Most likely there is no performance difference between "lock xadd [ptr], 1" and
"lock inc [ptr]", the increment instruction takes a byte less.
You can ask g++/clang++ for good ideas.
----
#include <atomic>
std::atomic<uint8_t> ubyte;
std::atomic<uint16_t> ushort;
std::atomic<uint32_t> uint;
std::atomic<uint64_t> ulong;
int main() {
++ubyte;
++ushort;
++uint;
++ulong;
}
----
It seems that we should rather implement the more generic fetch_add and
fetch_sub though.
http://en.cppreference.com/w/cpp/atomic/atomic/fetch_add
http://en.cppreference.com/w/cpp/atomic/atomic/fetch_sub
--
More information about the Digitalmars-d-bugs
mailing list