5 #ifndef FABCOIN_SUPPORT_LOCKEDPOOL_H 6 #define FABCOIN_SUPPORT_LOCKEDPOOL_H 30 virtual void*
AllocateLocked(
size_t len,
bool *lockingSuccess) = 0;
35 virtual void FreeLocked(
void* addr,
size_t len) = 0;
50 Arena(
void *base,
size_t size,
size_t alignment);
67 void* alloc(
size_t size);
125 static const size_t ARENA_SIZE = 256*1024;
129 static const size_t ARENA_ALIGN = 16;
133 typedef bool (*LockingFailed_Callback)();
153 LockedPool(std::unique_ptr<LockedPageAllocator> allocator, LockingFailed_Callback lf_cb_in = 0);
160 void* alloc(
size_t size);
166 void free(
void *ptr);
188 bool new_arena(
size_t size,
size_t align);
223 static void CreateInstance();
225 static bool LockingFailed();
231 #endif // FABCOIN_SUPPORT_LOCKEDPOOL_H
static std::once_flag init_flag
size_t alignment
Minimum chunk alignment.
std::mutex mutex
Mutex protects access to this pool's data structures, including arenas.
std::list< LockedPageArena > arenas
static LockedPoolManager & Instance()
Return the current instance, or create it once.
virtual void * AllocateLocked(size_t len, bool *lockingSuccess)=0
Allocate and lock memory pages.
LockingFailed_Callback lf_cb
bool addressInArena(void *ptr) const
Return whether a pointer points inside this arena.
OS-dependent allocation and deallocation of locked/pinned memory pages.
LockedPageAllocator * allocator
Singleton class to keep track of locked (ie, non-swappable) memory, for use in std::allocator templat...
char * end
End address of arena.
static LockedPoolManager * _instance
virtual void FreeLocked(void *addr, size_t len)=0
Unlock and free memory pages.
virtual ~LockedPageAllocator()
std::map< char *, size_t > chunks_used
Pool for locked memory chunks.
Create an arena from locked pages.
char * base
Base address of arena.
uint8_t const size_t const size
virtual size_t GetLimit()=0
Get the total limit on the amount of memory that may be locked by this process, in bytes...
static void CreateInstance()
Create a new LockedPoolManager specialized to the OS.
size_t cumulative_bytes_locked
std::map< char *, size_t > chunks_free
Map of chunk address to chunk information.
std::unique_ptr< LockedPageAllocator > allocator