From 72c5c3f3712eddb68cbcee3326e706353669174a Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 13 Apr 2017 21:50:16 +0200 Subject: [PATCH] Replace stdatomic.h (C11 standard compliant header) by a custom one to increase C++ compatibility as stdatomic.h doesn't work in C++! (I would like to thanks the one(s) who thought it was a good idea ***not*** to include stdatomic.h -and thread.h- in the C++ standard!) --- m-atomic.h | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ m-i-shared.h | 2 +- m-shared.h | 2 +- m-snapshot.h | 2 +- 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 m-atomic.h diff --git a/m-atomic.h b/m-atomic.h new file mode 100644 index 00000000..8c79a275 --- /dev/null +++ b/m-atomic.h @@ -0,0 +1,95 @@ +/* + * M*LIB - Thin stdatomic wrapper for C++ compatibility + * + * Copyright (c) 2017, Patrick Pelissier + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef __M_ATOMIC_H +#define __M_ATOMIC_H + +/* NOTE: Due to the C++ not having recognized stdatomic.h officialy, + it is hard to use this header directly with a C++ compiler like + g++ or MSVC. + (See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932 ). + clang has no issue with this header.*/ +#if defined(__cplusplus) && __cplusplus >= 201103L && !defined(__clang__) + +/* NOTE: This is what the stdatomic.h header shall do in C++ mode. */ +#include + +using std::memory_order; + +using std::atomic_bool; +using std::atomic_char; +using std::atomic_short; +using std::atomic_int; +using std::atomic_long; +using std::atomic_llong; +using std::atomic_uchar; +using std::atomic_schar; +using std::atomic_ushort; +using std::atomic_uint; +using std::atomic_ulong; +using std::atomic_ullong; +using std::atomic_intptr_t; +using std::atomic_uintptr_t; +using std::atomic_size_t; +using std::atomic_ptrdiff_t; +using std::atomic_intmax_t; +using std::atomic_uintmax_t; +using std::atomic_flag; + +using std::kill_dependency; +using std::atomic_thread_fence; +using std::atomic_signal_fence; +using std::atomic_is_lock_free; +using std::atomic_store_explicit; +using std::atomic_store; +using std::atomic_load_explicit; +using std::atomic_load; +using std::atomic_exchange_explicit; +using std::atomic_exchange; +using std::atomic_compare_exchange_strong_explicit; +using std::atomic_compare_exchange_strong; +using std::atomic_compare_exchange_weak_explicit; +using std::atomic_compare_exchange_weak; +using std::atomic_fetch_add; +using std::atomic_fetch_add_explicit; +using std::atomic_fetch_sub; +using std::atomic_fetch_sub_explicit; +using std::atomic_fetch_or; +using std::atomic_fetch_or_explicit; +using std::atomic_fetch_xor; +using std::atomic_fetch_xor_explicit; +using std::atomic_fetch_and; +using std::atomic_fetch_and_explicit; +using std::atomic_flag_test_and_set; +using std::atomic_flag_test_and_set_explicit; +using std::atomic_flag_clear; +using std::atomic_flag_clear_explicit; + +#else + +#include + +#endif + +#endif diff --git a/m-i-shared.h b/m-i-shared.h index 4ea6d4ce..327a50c4 100644 --- a/m-i-shared.h +++ b/m-i-shared.h @@ -28,9 +28,9 @@ #include #include #include -#include #include "m-core.h" +#include "m-atomic.h" /* Define the oplist of a intrusive shared pointer. USAGE: ISHARED_OPLIST(name [, oplist_of_the_type]) */ diff --git a/m-shared.h b/m-shared.h index 0bf2753b..64c07f38 100644 --- a/m-shared.h +++ b/m-shared.h @@ -28,10 +28,10 @@ #include #include #include -#include #include #include "m-core.h" +#include "m-atomic.h" /* Define the oplist of a shared pointer. USAGE: SHARED_OPLIST(name [, oplist_of_the_type]) */ diff --git a/m-snapshot.h b/m-snapshot.h index a56aaec2..2c6e8322 100644 --- a/m-snapshot.h +++ b/m-snapshot.h @@ -26,8 +26,8 @@ #define __M_SNAPSHOT #include -#include +#include "m-atomic.h" #include "m-core.h" /* Define a snapshot and it function