26#ifndef ROUTER_SRC_HARNESS_INCLUDE_SECURE_MEMORY_POOL_H_ 
   27#define ROUTER_SRC_HARNESS_INCLUDE_SECURE_MEMORY_POOL_H_ 
   33#include <unordered_map> 
   34#include <unordered_set> 
   37#include "harness_export.h"   
   66  [[nodiscard]] 
void *allocate(std::size_t 
size);
 
   74  void deallocate(
void *ptr, std::size_t 
size) 
noexcept;
 
   77  template <
class Strategy>
 
  105    [[nodiscard]] 
void *allocate_blocks(std::size_t 
count) 
noexcept;
 
  113    void deallocate_blocks(
void *ptr, std::size_t 
count) 
noexcept;
 
  116    [[nodiscard]] std::size_t find_contiguous_blocks(
 
  117        std::size_t 
count) 
const noexcept;
 
  119    void set_in_use(std::size_t 
index, std::size_t 
count) 
noexcept;
 
  121    void set_free(std::size_t 
index, std::size_t 
count) 
noexcept;
 
  154    [[nodiscard]] 
void *allocate_blocks(
std::
size_t count) noexcept;
 
  162    void deallocate_blocks(
void *ptr, 
std::
size_t count) noexcept;
 
  177  template <
class Strategy>
 
  188    Bucket(std::size_t bucket_size, std::size_t block_size);
 
  201    [[nodiscard]] inline 
std::
size_t bucket_size() const noexcept {
 
  215    [[nodiscard]] 
inline std::size_t 
block_size() const noexcept {
 
  229    [[nodiscard]] 
inline std::size_t 
is_empty() const noexcept {
 
  230      return block_count() == blocks_free();
 
  236    [[nodiscard]] 
inline std::size_t 
is_full() const noexcept {
 
  237      return 0 == blocks_free();
 
  248    [[nodiscard]] 
bool contains(
const void *ptr) 
const noexcept;
 
  258    [[nodiscard]] 
void *allocate(std::size_t bytes) 
noexcept;
 
  266    void deallocate(
void *ptr, std::size_t bytes) 
noexcept;
 
  272      return l.memory_ == 
r.memory_;
 
  290  template <
class BucketType>
 
  302    BucketPool(std::size_t page_size, std::size_t block_size);
 
  315    [[nodiscard]] 
inline std::size_t 
page_size() const noexcept {
 
  322    [[nodiscard]] 
inline std::size_t 
block_size() const noexcept {
 
  333    [[nodiscard]] 
void *allocate(std::size_t bytes);
 
  341    void deallocate(
void *ptr, std::size_t bytes) 
noexcept;
 
  347        return reinterpret_cast<std::size_t
>(b.memory());
 
  351    using Buckets = std::unordered_set<BucketType, BucketHash>;
 
  353    [[nodiscard]] 
static inline BucketType *
pointer(
 
  354        Buckets::const_iterator it) {
 
  359      return const_cast<BucketType *
>(&*it);
 
  362    [[nodiscard]] BucketType *add_bucket(std::size_t 
size);
 
  364    void remove_bucket(BucketType *
bucket);
 
  366    [[nodiscard]] BucketType *find_bucket(
const void *ptr);
 
Holds buckets with the given block size.
Definition: secure_memory_pool.h:291
 
const std::size_t block_size_
Definition: secure_memory_pool.h:369
 
Buckets buckets_
Definition: secure_memory_pool.h:374
 
std::size_t page_size() const noexcept
Page size for the buckets in this pool.
Definition: secure_memory_pool.h:315
 
const std::size_t page_size_
Definition: secure_memory_pool.h:368
 
std::unordered_set< BucketType, BucketHash > Buckets
Definition: secure_memory_pool.h:351
 
Buckets full_buckets_
Definition: secure_memory_pool.h:376
 
BucketPool & operator=(const BucketPool &)=delete
 
std::mutex mutex_
Definition: secure_memory_pool.h:371
 
std::unordered_map< const void *, BucketType * > memory_map_
Definition: secure_memory_pool.h:380
 
std::size_t block_size() const noexcept
Size of a single block of memory.
Definition: secure_memory_pool.h:322
 
static BucketType * pointer(Buckets::const_iterator it)
Definition: secure_memory_pool.h:353
 
BucketPool & operator=(BucketPool &&)=delete
 
BucketPool(const BucketPool &)=delete
 
BucketPool(BucketPool &&)=delete
 
const BucketType * empty_bucket_
Definition: secure_memory_pool.h:384
 
A bucket of memory blocks of the given size.
Definition: secure_memory_pool.h:178
 
const std::size_t block_count_
Definition: secure_memory_pool.h:277
 
Bucket(const Bucket &)=delete
 
std::size_t block_size() const noexcept
Size of a single block of memory.
Definition: secure_memory_pool.h:215
 
std::size_t block_count() const noexcept
Number of memory blocks in this bucket.
Definition: secure_memory_pool.h:208
 
std::byte * memory_
Definition: secure_memory_pool.h:282
 
const std::size_t bucket_size_
Definition: secure_memory_pool.h:276
 
std::size_t blocks_free_
Definition: secure_memory_pool.h:279
 
friend bool operator==(const Bucket &l, const Bucket &r) noexcept
Compares two buckets.
Definition: secure_memory_pool.h:271
 
std::size_t is_empty() const noexcept
Whether all blocks are unused.
Definition: secure_memory_pool.h:229
 
const std::size_t block_size_
Definition: secure_memory_pool.h:278
 
std::size_t is_full() const noexcept
Whether all blocks are being used.
Definition: secure_memory_pool.h:236
 
Strategy allocator_
Definition: secure_memory_pool.h:284
 
std::size_t blocks_free() const noexcept
Number of unused blocks.
Definition: secure_memory_pool.h:222
 
std::byte * memory() const noexcept
Pointer to the memory held by this bucket.
Definition: secure_memory_pool.h:243
 
Allows to allocate multiple contiguous blocks of memory.
Definition: secure_memory_pool.h:83
 
ContiguousBlocks & operator=(ContiguousBlocks &&)=delete
 
ContiguousBlocks(const ContiguousBlocks &)=delete
 
const Bucket< ContiguousBlocks > & parent_
Definition: secure_memory_pool.h:123
 
ContiguousBlocks()=delete
 
ContiguousBlocks & operator=(const ContiguousBlocks &)=delete
 
unsigned char * index_
Definition: secure_memory_pool.h:126
 
ContiguousBlocks(ContiguousBlocks &&)=delete
 
Allocates a single block of memory.
Definition: secure_memory_pool.h:132
 
FixedBlock(const FixedBlock &)=delete
 
const Bucket< FixedBlock > & parent_
Definition: secure_memory_pool.h:169
 
BlockList * unused_blocks_
Definition: secure_memory_pool.h:171
 
Manages a pool of memory which is prevented from being swapped.
Definition: secure_memory_pool.h:44
 
BucketPool< Bucket< ContiguousBlocks > > large_pool_
Definition: secure_memory_pool.h:394
 
std::vector< Bucket< FixedBlock > > fixed_buckets_
Definition: secure_memory_pool.h:390
 
SecureMemoryPool(SecureMemoryPool &&)=delete
 
~SecureMemoryPool()=default
 
SecureMemoryPool & operator=(SecureMemoryPool &&)=delete
 
SecureMemoryPool & operator=(const SecureMemoryPool &)=delete
 
std::vector< std::mutex > fixed_buckets_mutexes_
Definition: secure_memory_pool.h:392
 
SecureMemoryPool(const SecureMemoryPool &)=delete
 
static bool contains(const std::vector< std::string > &container, const std::string &file)
Definition: config_files.cc:41
 
unsigned char byte
Blob class.
Definition: common.h:151
 
static int count
Definition: myisam_ftdump.cc:45
 
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
 
static mysql_service_status_t get(THD **thd) noexcept
Definition: mysql_current_thread_reader_all_empty.cc:31
 
size_t size(const char *const c)
Definition: base64.h:46
 
Definition: gcs_xcom_synode.h:64
 
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
 
Definition: completion_hash.h:40
 
Definition: secure_memory_pool.h:344
 
std::size_t operator()(const BucketType &b) const noexcept
Definition: secure_memory_pool.h:345
 
Definition: secure_memory_pool.h:165
 
BlockList * next
Definition: secure_memory_pool.h:166