From 25b030b85a03c86a010c1d2e4bc8db25958b0515 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 15 Aug 2018 10:56:33 +0100 Subject: [PATCH] Fix single-threaded build for targets without atomics * src/c++17/memory_resource.cc [!_GLIBCXX_HAS_GTHREADS] (atomic_mem_res): Add unsynchronized definition for single-threaded. From-SVN: r263554 --- libstdc++-v3/ChangeLog | 5 +++++ libstdc++-v3/src/c++17/memory_resource.cc | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 182c0ed2ff3..15d2eb5eee9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2018-08-15 Jonathan Wakely + + * src/c++17/memory_resource.cc [!_GLIBCXX_HAS_GTHREADS] + (atomic_mem_res): Add unsynchronized definition for single-threaded. + 2018-08-14 Jonathan Wakely PR libstdc++/86954 diff --git a/libstdc++-v3/src/c++17/memory_resource.cc b/libstdc++-v3/src/c++17/memory_resource.cc index bd8f32d931e..aa82813e645 100644 --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -88,7 +88,7 @@ namespace pmr #if ATOMIC_POINTER_LOCK_FREE == 2 using atomic_mem_res = atomic; # define _GLIBCXX_ATOMIC_MEM_RES_CAN_BE_CONSTANT_INITIALIZED -#else +#elif defined(_GLIBCXX_HAS_GTHREADS) // Can't use pointer-width atomics, define a type using a mutex instead: struct atomic_mem_res { @@ -114,6 +114,26 @@ namespace pmr return std::exchange(val, r); } }; +#else +# define _GLIBCXX_ATOMIC_MEM_RES_CAN_BE_CONSTANT_INITIALIZED + // Single-threaded, no need for synchronization + struct atomic_mem_res + { + constexpr + atomic_mem_res(memory_resource* r) : val(r) { } + + memory_resource* val; + + memory_resource* load() const + { + return val; + } + + memory_resource* exchange(memory_resource* r) + { + return std::exchange(val, r); + } + }; #endif // ATOMIC_POINTER_LOCK_FREE == 2 #ifdef _GLIBCXX_ATOMIC_MEM_RES_CAN_BE_CONSTANT_INITIALIZED -- 2.30.2