Automatically enable C11 atomics when available. It's now 2021. Hopefully we can at least assume anyone building with -std=c11 also has a corresponding set of headers. Plus, even if you don't, Clang seems to provide a header. (So C11 atomics work in clang-cl.) Also apparently atomics are optional, so this checks __STDC_NO_ATOMICS__. This does *not* set C11 as the minimum version. If you build with -std=c99, we'll silently use the non-atomics implementation. That's a little magical, so I've kept OPENSSL_C11_ATOMIC as a way to assert that you really want C11 atomics. Mostly it turns into a -std=c11 && !MSVC self-assert. Update-Note: If something fails to compile, we'll revert this and adjust the check, or add an opt-out, or give up. Also, if building with -std=c99, consider -std=c11. Change-Id: I1a8074c367a765c5a0f087db8c250e050df2dde8 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/46344 Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/internal.h b/crypto/internal.h index c574645..51d1d9c 100644 --- a/crypto/internal.h +++ b/crypto/internal.h
@@ -471,6 +471,12 @@ // Reference counting. +// Automatically enable C11 atomics if implemented. +#if !defined(OPENSSL_C11_ATOMIC) && !defined(__STDC_NO_ATOMICS__) && \ + defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define OPENSSL_C11_ATOMIC +#endif + // CRYPTO_REFCOUNT_MAX is the value at which the reference count saturates. #define CRYPTO_REFCOUNT_MAX 0xffffffff