diff options
author | David Goldblatt <davidgoldblatt@fb.com> | 2017-01-25 17:54:27 (GMT) |
---|---|---|
committer | David Goldblatt <davidtgoldblatt@gmail.com> | 2017-03-03 21:40:59 (GMT) |
commit | d4ac7582f32f506d5203bea2f0115076202add38 (patch) | |
tree | c7a84707cc1a41c9ef6a7d4e692e48ff6fa8ee77 /src/atomic.c | |
parent | 957b8c5f2171f54f66689875144830e682be8e64 (diff) | |
download | jemalloc-d4ac7582f32f506d5203bea2f0115076202add38.zip jemalloc-d4ac7582f32f506d5203bea2f0115076202add38.tar.gz jemalloc-d4ac7582f32f506d5203bea2f0115076202add38.tar.bz2 |
Introduce a backport of C11 atomics
This introduces a backport of C11 atomics. It has four implementations; ranked
in order of preference, they are:
- GCC/Clang __atomic builtins
- GCC/Clang __sync builtins
- MSVC _Interlocked builtins
- C11 atomics, from <stdatomic.h>
The primary advantages are:
- Close adherence to the standard API gives us a defined memory model.
- Type safety: atomic objects are now separate types from non-atomic ones, so
that it's impossible to mix up atomic and non-atomic updates (which is
undefined behavior that compilers are starting to take advantage of).
- Efficiency: we can specify ordering for operations, avoiding fences and
atomic operations on strongly ordered architectures (example:
`atomic_write_u32(ptr, val);` involves a CAS loop, whereas
`atomic_store(ptr, val, ATOMIC_RELEASE);` is a plain store.
This diff leaves in the current atomics API (implementing them in terms of the
backport). This lets us transition uses over piecemeal.
Testing:
This is by nature hard to test. I've manually tested the first three options on
Linux on gcc by futzing with the #defines manually, on freebsd with gcc and
clang, on MSVC, and on OS X with clang. All of these were x86 machines though,
and we don't have any test infrastructure set up for non-x86 platforms.
Diffstat (limited to 'src/atomic.c')
-rw-r--r-- | src/atomic.c | 2 |
1 files changed, 0 insertions, 2 deletions
diff --git a/src/atomic.c b/src/atomic.c deleted file mode 100644 index 9871390..0000000 --- a/src/atomic.c +++ /dev/null @@ -1,2 +0,0 @@ -#define JEMALLOC_ATOMIC_C_ -#include "jemalloc/internal/jemalloc_internal.h" |