Changeset View
Changeset View
Standalone View
Standalone View
src/support/lockedpool.h
Show First 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | public: | ||||
* Create a new LockedPool. This takes ownership of the MemoryPageLocker, | * Create a new LockedPool. This takes ownership of the MemoryPageLocker, | ||||
* you can only instantiate this with LockedPool(std::move(...)). | * you can only instantiate this with LockedPool(std::move(...)). | ||||
* | * | ||||
* The second argument is an optional callback when locking a newly | * The second argument is an optional callback when locking a newly | ||||
* allocated arena failed. If this callback is provided and returns false, | * allocated arena failed. If this callback is provided and returns false, | ||||
* the allocation fails (hard fail), if it returns true the allocation | * the allocation fails (hard fail), if it returns true the allocation | ||||
* proceeds, but it could warn. | * proceeds, but it could warn. | ||||
*/ | */ | ||||
LockedPool(std::unique_ptr<LockedPageAllocator> allocator, | explicit LockedPool(std::unique_ptr<LockedPageAllocator> allocator, | ||||
LockingFailed_Callback lf_cb_in = nullptr); | LockingFailed_Callback lf_cb_in = nullptr); | ||||
~LockedPool(); | ~LockedPool(); | ||||
/** | /** | ||||
* Allocate size bytes from this arena. | * Allocate size bytes from this arena. | ||||
* Returns pointer on success, or 0 if memory is full or the application | * Returns pointer on success, or 0 if memory is full or the application | ||||
* tried to allocate 0 bytes. | * tried to allocate 0 bytes. | ||||
*/ | */ | ||||
void *alloc(size_t size); | void *alloc(size_t size); | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | 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, | std::call_once(LockedPoolManager::init_flag, | ||||
LockedPoolManager::CreateInstance); | LockedPoolManager::CreateInstance); | ||||
return *LockedPoolManager::_instance; | return *LockedPoolManager::_instance; | ||||
} | } | ||||
private: | private: | ||||
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; | static std::once_flag init_flag; | ||||
}; | }; | ||||
#endif // BITCOIN_SUPPORT_LOCKEDPOOL_H | #endif // BITCOIN_SUPPORT_LOCKEDPOOL_H |