+2018-08-15 Jonathan Wakely <jwakely@redhat.com>
+
+ * src/c++17/memory_resource.cc [!_GLIBCXX_HAS_GTHREADS]
+ (atomic_mem_res): Add unsynchronized definition for single-threaded.
+
2018-08-14 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/86954
#if ATOMIC_POINTER_LOCK_FREE == 2
using atomic_mem_res = atomic<memory_resource*>;
# 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
{
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