Changeset View
Changeset View
Standalone View
Standalone View
src/support/lockedpool.h
// Copyright (c) 2016 The Bitcoin Core developers | // Copyright (c) 2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_SUPPORT_LOCKEDPOOL_H | #ifndef BITCOIN_SUPPORT_LOCKEDPOOL_H | ||||
#define BITCOIN_SUPPORT_LOCKEDPOOL_H | #define BITCOIN_SUPPORT_LOCKEDPOOL_H | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <list> | #include <list> | ||||
#include <map> | #include <map> | ||||
#include <memory> | #include <memory> | ||||
#include <mutex> | #include <mutex> | ||||
#include <unordered_map> | |||||
/** | /** | ||||
* OS-dependent allocation and deallocation of locked/pinned memory pages. | * OS-dependent allocation and deallocation of locked/pinned memory pages. | ||||
* Abstract base class. | * Abstract base class. | ||||
*/ | */ | ||||
class LockedPageAllocator { | class LockedPageAllocator { | ||||
public: | public: | ||||
virtual ~LockedPageAllocator() {} | virtual ~LockedPageAllocator() {} | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | #endif | ||||
/** | /** | ||||
* Return whether a pointer points inside this arena. | * Return whether a pointer points inside this arena. | ||||
* This returns base <= ptr < (base+size) so only use it for (inclusive) | * This returns base <= ptr < (base+size) so only use it for (inclusive) | ||||
* chunk starting addresses. | * chunk starting addresses. | ||||
*/ | */ | ||||
bool addressInArena(void *ptr) const { return ptr >= base && ptr < end; } | bool addressInArena(void *ptr) const { return ptr >= base && ptr < end; } | ||||
private: | private: | ||||
/** | typedef std::multimap<size_t, char *> SizeToChunkSortedMap; | ||||
* Map of chunk address to chunk information. This class makes use of the | /** Map to enable O(log(n)) best-fit allocation, as it's sorted by size */ | ||||
* sorted order to merge previous and next chunks during deallocation. | SizeToChunkSortedMap size_to_free_chunk; | ||||
*/ | |||||
std::map<char *, size_t> chunks_free; | typedef std::unordered_map<char *, SizeToChunkSortedMap::const_iterator> | ||||
std::map<char *, size_t> chunks_used; | ChunkToSizeMap; | ||||
/** Map from begin of free chunk to its node in size_to_free_chunk */ | |||||
ChunkToSizeMap chunks_free; | |||||
/** Map from end of free chunk to its node in size_to_free_chunk */ | |||||
ChunkToSizeMap chunks_free_end; | |||||
/** Map from begin of used chunk to its size */ | |||||
std::unordered_map<char *, size_t> chunks_used; | |||||
/** Base address of arena */ | /** Base address of arena */ | ||||
char *base; | char *base; | ||||
/** End address of arena */ | /** End address of arena */ | ||||
char *end; | char *end; | ||||
/** Minimum chunk alignment */ | /** Minimum chunk alignment */ | ||||
size_t alignment; | size_t alignment; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 137 Lines • Show Last 20 Lines |