summaryrefslogtreecommitdiff
path: root/src/experimental/memory_resource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/experimental/memory_resource.cpp')
-rw-r--r--src/experimental/memory_resource.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/experimental/memory_resource.cpp b/src/experimental/memory_resource.cpp
index c01eb0823bae..3e87a2dedded 100644
--- a/src/experimental/memory_resource.cpp
+++ b/src/experimental/memory_resource.cpp
@@ -50,11 +50,7 @@ public:
protected:
virtual void* do_allocate(size_t, size_t) {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw std::bad_alloc();
-#else
- abort();
-#endif
+ __throw_bad_alloc();
}
virtual void do_deallocate(void *, size_t, size_t) {}
virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT
@@ -74,7 +70,10 @@ union ResourceInitHelper {
};
// When compiled in C++14 this initialization should be a constant expression.
// Only in C++11 is "init_priority" needed to ensure initialization order.
-ResourceInitHelper res_init __attribute__((init_priority (101)));
+#if _LIBCPP_STD_VER > 11
+_LIBCPP_SAFE_STATIC
+#endif
+ResourceInitHelper res_init __attribute__((init_priority (101)));
} // end namespace
@@ -93,7 +92,7 @@ static memory_resource *
__default_memory_resource(bool set = false, memory_resource * new_res = nullptr) _NOEXCEPT
{
#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
- static atomic<memory_resource*> __res =
+ _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res =
ATOMIC_VAR_INIT(&res_init.resources.new_delete_res);
if (set) {
new_res = new_res ? new_res : new_delete_resource();
@@ -106,7 +105,7 @@ __default_memory_resource(bool set = false, memory_resource * new_res = nullptr)
&__res, memory_order::memory_order_acquire);
}
#elif !defined(_LIBCPP_HAS_NO_THREADS)
- static memory_resource * res = &res_init.resources.new_delete_res;
+ _LIBCPP_SAFE_STATIC static memory_resource * res = &res_init.resources.new_delete_res;
static mutex res_lock;
if (set) {
new_res = new_res ? new_res : new_delete_resource();
@@ -119,7 +118,7 @@ __default_memory_resource(bool set = false, memory_resource * new_res = nullptr)
return res;
}
#else
- static memory_resource* res = &res_init.resources.new_delete_res;
+ _LIBCPP_SAFE_STATIC static memory_resource* res = &res_init.resources.new_delete_res;
if (set) {
new_res = new_res ? new_res : new_delete_resource();
memory_resource * old_res = res;