diff options
author | thegeorg <thegeorg@yandex-team.com> | 2022-10-01 18:07:17 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2022-10-01 18:07:17 +0300 |
commit | 1d09e53ce511b3bf866fea0829451fc931fa939c (patch) | |
tree | 1db29227480c126ef9a34c954fc22e7afd6b6620 | |
parent | fecbe41234ec99b7709d8d9ec617219655ac51a7 (diff) | |
download | ydb-1d09e53ce511b3bf866fea0829451fc931fa939c.tar.gz |
Backport PR #232 to allow pmr usage in pre-main
-rw-r--r-- | contrib/restricted/boost/container/src/global_resource.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/contrib/restricted/boost/container/src/global_resource.cpp b/contrib/restricted/boost/container/src/global_resource.cpp index 69a91c3cf0..b3fa7611ca 100644 --- a/contrib/restricted/boost/container/src/global_resource.cpp +++ b/contrib/restricted/boost/container/src/global_resource.cpp @@ -77,7 +77,7 @@ BOOST_CONTAINER_DECL memory_resource* null_memory_resource() BOOST_NOEXCEPT return &boost::container::dtl::singleton_default<null_memory_resource_imp>::instance(); } -#if 1 +#if defined(BOOST_NO_CXX11_HDR_ATOMIC) static memory_resource *default_memory_resource = &boost::container::dtl::singleton_default<new_delete_resource_imp>::instance(); @@ -127,17 +127,19 @@ namespace boost { namespace container { namespace pmr { -static std::atomic<memory_resource*> default_memory_resource = - ATOMIC_VAR_INIT(&boost::container::dtl::singleton_default<new_delete_resource_imp>::instance()); +std::atomic<memory_resource*>& default_memory_resource_instance() { + static std::atomic<memory_resource*> instance = new_delete_resource(); + return instance; +} BOOST_CONTAINER_DECL memory_resource* set_default_resource(memory_resource* r) BOOST_NOEXCEPT { memory_resource *const res = r ? r : new_delete_resource(); - return default_memory_resource.exchange(res, std::memory_order_acq_rel); + return default_memory_resource_instance().exchange(res, std::memory_order_acq_rel); } BOOST_CONTAINER_DECL memory_resource* get_default_resource() BOOST_NOEXCEPT -{ return default_memory_resource.load(std::memory_order_acquire); } +{ return default_memory_resource_instance().load(std::memory_order_acquire); } #endif |