Commit 25878e4b authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Let noexcept StaticSingletonManager::create be outline

Summary: [Folly] Let `noexcept` member function template `StaticSingletonManager::create` be outline to avoid pathological inline path behavior.

Reviewed By: iahs

Differential Revision: D23522488

fbshipit-source-id: 5ec9ed271b814f4496812e226e0f0929f65565a2
parent 1c185362
...@@ -28,11 +28,13 @@ namespace { ...@@ -28,11 +28,13 @@ namespace {
class StaticSingletonManagerWithRttiImpl { class StaticSingletonManagerWithRttiImpl {
public: public:
using Make = void*(); using Make = void*();
using Cache = std::atomic<void*>;
void* create(std::type_info const& key, Make& make, Cache& cache) { template <typename Arg>
auto const ptr = entry(key).get(make); static void* create(Arg& arg) {
cache.store(ptr, std::memory_order_release); // This Leaky Meyers Singleton must always live in the .cpp file.
static auto& instance = *new StaticSingletonManagerWithRttiImpl();
auto const ptr = instance.entry(*arg.key).get(arg.make);
arg.cache.store(ptr, std::memory_order_release);
return ptr; return ptr;
} }
...@@ -59,11 +61,13 @@ class StaticSingletonManagerWithRttiImpl { ...@@ -59,11 +61,13 @@ class StaticSingletonManagerWithRttiImpl {
} // namespace } // namespace
void* StaticSingletonManagerWithRtti::create_(Arg& arg) { template <bool Noexcept>
// This Leaky Meyers Singleton must always live in the .cpp file. void* StaticSingletonManagerWithRtti::create_(Arg& arg) noexcept(Noexcept) {
static auto& instance = *new StaticSingletonManagerWithRttiImpl(); return StaticSingletonManagerWithRttiImpl::create(arg);
return instance.create(*arg.key, arg.make, arg.cache);
} }
template void* StaticSingletonManagerWithRtti::create_<false>(Arg& arg);
template void* StaticSingletonManagerWithRtti::create_<true>(Arg& arg);
} // namespace detail } // namespace detail
} // namespace folly } // namespace folly
...@@ -81,10 +81,7 @@ class StaticSingletonManagerWithRtti { ...@@ -81,10 +81,7 @@ class StaticSingletonManagerWithRtti {
} }
template <bool Noexcept> template <bool Noexcept>
FOLLY_ERASE static void* create_(Arg& arg) noexcept(Noexcept) { FOLLY_NOINLINE static void* create_(Arg& arg) noexcept(Noexcept);
return create_(arg);
}
FOLLY_NOINLINE static void* create_(Arg& arg);
}; };
using StaticSingletonManager = std::conditional_t< using StaticSingletonManager = std::conditional_t<
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment