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 {
class StaticSingletonManagerWithRttiImpl {
public:
using Make = void*();
using Cache = std::atomic<void*>;
void* create(std::type_info const& key, Make& make, Cache& cache) {
auto const ptr = entry(key).get(make);
cache.store(ptr, std::memory_order_release);
template <typename Arg>
static void* create(Arg& arg) {
// 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;
}
......@@ -59,11 +61,13 @@ class StaticSingletonManagerWithRttiImpl {
} // namespace
void* StaticSingletonManagerWithRtti::create_(Arg& arg) {
// This Leaky Meyers Singleton must always live in the .cpp file.
static auto& instance = *new StaticSingletonManagerWithRttiImpl();
return instance.create(*arg.key, arg.make, arg.cache);
template <bool Noexcept>
void* StaticSingletonManagerWithRtti::create_(Arg& arg) noexcept(Noexcept) {
return StaticSingletonManagerWithRttiImpl::create(arg);
}
template void* StaticSingletonManagerWithRtti::create_<false>(Arg& arg);
template void* StaticSingletonManagerWithRtti::create_<true>(Arg& arg);
} // namespace detail
} // namespace folly
......@@ -81,10 +81,7 @@ class StaticSingletonManagerWithRtti {
}
template <bool Noexcept>
FOLLY_ERASE static void* create_(Arg& arg) noexcept(Noexcept) {
return create_(arg);
}
FOLLY_NOINLINE static void* create_(Arg& arg);
FOLLY_NOINLINE static void* create_(Arg& arg) noexcept(Noexcept);
};
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