proxygen
|
#include <Singleton.h>
Classes | |
struct | ScopedExpunger |
Public Types | |
enum | Type { Type::Strict, Type::Relaxed } |
typedef std::function< void(void *)> | TeardownFunc |
typedef std::function< void *(void)> | CreateFunc |
typedef std::string(* | StackTraceGetterPtr) () |
Public Member Functions | |
SingletonVault (Type type=defaultVaultType()) | |
~SingletonVault () | |
void | registerSingleton (detail::SingletonHolderBase *entry) |
void | addEagerInitSingleton (detail::SingletonHolderBase *entry) |
void | registrationComplete () |
void | doEagerInit () |
void | doEagerInitVia (Executor &exe, folly::Baton<> *done=nullptr) |
void | destroyInstances () |
void | reenableInstances () |
size_t | registeredSingletonCount () const |
bool | eagerInitComplete () const |
size_t | livingSingletonCount () const |
void | setType (Type type) |
Static Public Member Functions | |
static Type | defaultVaultType () |
static SingletonVault * | singleton () |
template<typename VaultTag = detail::DefaultTag> | |
static SingletonVault * | singleton () |
static std::atomic< StackTraceGetterPtr > & | stackTraceGetter () |
Private Types | |
typedef std::unordered_map< detail::TypeDescriptor, detail::SingletonHolderBase *, detail::TypeDescriptorHasher > | SingletonMap |
Static Private Member Functions | |
static void | scheduleDestroyInstances () |
Private Attributes | |
Synchronized< SingletonMap, SharedMutexSuppressTSAN > | singletons_ |
Synchronized< std::unordered_set< detail::SingletonHolderBase * >, SharedMutexSuppressTSAN > | eagerInitSingletons_ |
Synchronized< std::vector< detail::TypeDescriptor >, SharedMutexSuppressTSAN > | creationOrder_ |
Synchronized< detail::SingletonVaultState, SharedMutexReadPriority > | state_ |
Type | type_ |
Friends | |
template<typename T > | |
struct | detail::SingletonHolder |
Definition at line 375 of file Singleton.h.
typedef std::function<void*(void)> folly::SingletonVault::CreateFunc |
Definition at line 415 of file Singleton.h.
|
private |
Definition at line 541 of file Singleton.h.
typedef std::string(* folly::SingletonVault::StackTraceGetterPtr) () |
Definition at line 508 of file Singleton.h.
typedef std::function<void(void*)> folly::SingletonVault::TeardownFunc |
Definition at line 414 of file Singleton.h.
|
strong |
Enumerator | |
---|---|
Strict | |
Relaxed |
Definition at line 377 of file Singleton.h.
|
inlineexplicit |
Definition at line 409 of file Singleton.h.
folly::SingletonVault::~SingletonVault | ( | ) |
Definition at line 221 of file Singleton.cpp.
void folly::SingletonVault::addEagerInitSingleton | ( | detail::SingletonHolderBase * | entry | ) |
Called by Singleton<T>.shouldEagerInit()
to ensure the instance is built when doEagerInit[Via]
is called; see those methods for more info.
Definition at line 238 of file Singleton.cpp.
References CHECK_THROW, folly::detail::SingletonVaultState::Running, folly::detail::SingletonHolderBase::type(), and UNLIKELY.
|
static |
Definition at line 51 of file Singleton.cpp.
References folly::detail::singleton_hs_init_weak().
void folly::SingletonVault::destroyInstances | ( | ) |
Definition at line 328 of file Singleton.cpp.
References folly::detail::SingletonVaultState::Quiescing.
Referenced by folly::SingletonVault::ScopedExpunger::expunge(), registrationComplete(), scheduleDestroyInstances(), TEST(), and folly::Init::~Init().
void folly::SingletonVault::doEagerInit | ( | ) |
Initialize all singletons which were marked as eager-initialized (using shouldEagerInit()
). No return value. Propagates exceptions from constructors / create functions, as is the usual case when calling for example Singleton<Foo>::get_weak()
.
Definition at line 276 of file Singleton.cpp.
References folly::detail::SingletonVaultState::Running, single, and UNLIKELY.
void folly::SingletonVault::doEagerInitVia | ( | Executor & | exe, |
folly::Baton<> * | done = nullptr |
||
) |
Schedule eager singletons' initializations through the given executor. If baton ptr is not null, its post
method is called after all early initialization has completed.
If exceptions are thrown during initialization, this method will still post
the baton to indicate completion. The exception will not propagate and future attempts to try_get
or get_weak
the failed singleton will retry initialization.
Sample usage:
folly::IOThreadPoolExecutor executor(max_concurrency_level); folly::Baton<> done; doEagerInitVia(executor, &done); done.wait(); // or 'try_wait_for', etc.
Definition at line 291 of file Singleton.cpp.
References folly::Executor::add(), folly::Baton< MayBlock, Atom >::post(), folly::detail::SingletonVaultState::Running, SCOPE_EXIT, single, and UNLIKELY.
bool folly::SingletonVault::eagerInitComplete | ( | ) | const |
Flips to true if eager initialization was used, and has completed. Never set to true if "doEagerInit()" or "doEagerInitVia" never called.
|
inline |
Definition at line 480 of file Singleton.h.
void folly::SingletonVault::reenableInstances | ( | ) |
Definition at line 372 of file Singleton.cpp.
References folly::detail::SingletonVaultState::Quiescing, and folly::detail::SingletonVaultState::Running.
Referenced by folly::SingletonVault::ScopedExpunger::expunge().
|
inline |
Definition at line 470 of file Singleton.h.
void folly::SingletonVault::registerSingleton | ( | detail::SingletonHolderBase * | entry | ) |
Definition at line 225 of file Singleton.cpp.
References CHECK_THROW, folly::detail::SingletonVaultState::Running, folly::detail::SingletonHolderBase::type(), and UNLIKELY.
void folly::SingletonVault::registrationComplete | ( | ) |
Definition at line 252 of file Singleton.cpp.
References destroyInstances(), folly::detail::SingletonVaultState::Running, singleton(), and type_.
Referenced by folly::init().
|
staticprivate |
Definition at line 380 of file Singleton.cpp.
References __attribute__(), destroyInstances(), folly::symbolizer::getStackTraceSafe(), folly::threadlocal_detail::StaticMeta< Tag, AccessMode >::instance(), testing::kMaxStackTraceDepth, folly::symbolizer::SymbolizePrinter::println(), singleton(), stackTraceGetter(), folly::symbolizer::StringSymbolizePrinter::str(), string, and folly::symbolizer::Symbolizer::symbolize().
Referenced by folly::detail::SingletonHolder< T >::createInstance().
|
inline |
Definition at line 516 of file Singleton.h.
|
inlinestatic |
Definition at line 495 of file Singleton.h.
Referenced by folly::init(), registrationComplete(), scheduleDestroyInstances(), TEST(), and folly::Init::~Init().
|
inlinestatic |
Definition at line 502 of file Singleton.h.
|
inlinestatic |
Definition at line 510 of file Singleton.h.
Referenced by proxygen::logging_details::getStackTrace(), scheduleDestroyInstances(), folly::detail::singletonPrintDestructionStackTrace(), folly::detail::singletonWarnCreateBeforeRegistrationCompleteAndAbort(), folly::detail::singletonWarnCreateUnregisteredAndAbort(), and folly::detail::singletonWarnLeakyInstantiatingNotRegisteredAndAbort().
|
friend |
Definition at line 522 of file Singleton.h.
|
private |
Definition at line 552 of file Singleton.h.
Referenced by folly::detail::SingletonHolder< T >::createInstance().
|
private |
Definition at line 550 of file Singleton.h.
|
private |
Definition at line 546 of file Singleton.h.
|
private |
Definition at line 557 of file Singleton.h.
Referenced by folly::detail::SingletonHolder< T >::createInstance().
|
private |
Definition at line 559 of file Singleton.h.
Referenced by folly::detail::SingletonHolder< T >::createInstance().