Changeset View
Changeset View
Standalone View
Standalone View
src/support/lockedpool.h
Show First 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | |||||
* have to make sure the LockedPoolManager instance exists before any other | * have to make sure the LockedPoolManager instance exists before any other | ||||
* STL-based objects that use secure_allocator are created. So instead of having | * STL-based objects that use secure_allocator are created. So instead of having | ||||
* LockedPoolManager also be static-initialized, it is created on demand. | * LockedPoolManager also be static-initialized, it is created on demand. | ||||
*/ | */ | ||||
class LockedPoolManager : public LockedPool { | class LockedPoolManager : public LockedPool { | ||||
public: | public: | ||||
/** Return the current instance, or create it once */ | /** Return the current instance, or create it once */ | ||||
static LockedPoolManager &Instance() { | static LockedPoolManager &Instance() { | ||||
std::call_once(LockedPoolManager::init_flag, | static std::once_flag init_flag; | ||||
LockedPoolManager::CreateInstance); | std::call_once(init_flag, LockedPoolManager::CreateInstance); | ||||
return *LockedPoolManager::_instance; | return *LockedPoolManager::_instance; | ||||
} | } | ||||
private: | private: | ||||
explicit LockedPoolManager(std::unique_ptr<LockedPageAllocator> allocator); | explicit LockedPoolManager(std::unique_ptr<LockedPageAllocator> allocator); | ||||
/** Create a new LockedPoolManager specialized to the OS */ | /** Create a new LockedPoolManager specialized to the OS */ | ||||
static void CreateInstance(); | static void CreateInstance(); | ||||
/** Called when locking fails, warn the user here */ | /** Called when locking fails, warn the user here */ | ||||
static bool LockingFailed(); | static bool LockingFailed(); | ||||
static LockedPoolManager *_instance; | static LockedPoolManager *_instance; | ||||
static std::once_flag init_flag; | |||||
}; | }; | ||||
#endif // BITCOIN_SUPPORT_LOCKEDPOOL_H | #endif // BITCOIN_SUPPORT_LOCKEDPOOL_H |