pstore2
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
pstore::storage Class Reference

Classes

struct  copy_from_store_traits
 
struct  copy_to_store_traits
 

Public Types

using region_container = std::vector< region::memory_mapper_ptr >
 

Public Member Functions

 PSTORE_STATIC_ASSERT (full_region_size % min_region_size==0)
 
template<typename File >
 storage (std::shared_ptr< File > const &file, std::unique_ptr< system_page_size_interface > &&page_size, std::unique_ptr< region::factory > &&region_factory)
 
template<typename File >
 storage (std::shared_ptr< File > const &file)
 
file::file_basefile () noexcept
 
file::file_base const * file () const noexcept
 
void map_bytes (std::uint64_t new_size)
 
void update_master_pointers (std::size_t old_length)
 Called to add newly created memory-mapped regions to the segment address table. More...
 
template<typename Traits , typename Function >
void copy (address addr, std::size_t size, typename Traits::temp_pointer p, Function copier) const
 This function performs the bulk of the work of creating a "shadow" block when a request spans more than one memory-mapped region (or when PSTORE_ALWAYS_SPANNING is enabled). More...
 
bool request_spans_regions (address const &addr, std::size_t size) const noexcept
 Returns true if the given address range "spans" more than one region. More...
 
void protect (address first, address last)
 Marks the address range [first, last) as read-only.
 
region_container const & regions () const
 
std::shared_ptr< void const > segment_base (address::segment_type const segment) const noexcept
 
std::shared_ptr< void > const & segment_base (address::segment_type const segment) noexcept
 
std::shared_ptr< void const > address_to_pointer (address const addr) const noexcept
 
std::shared_ptr< void > address_to_pointer (address const addr) noexcept
 
template<typename T >
std::shared_ptr< T const > address_to_pointer (typed_address< T > addr) const noexcept
 
template<typename T >
std::shared_ptr< T > address_to_pointer (typed_address< T > addr) noexcept
 

Static Public Attributes

static auto constexpr full_region_size = UINT64_C (1) << 32U
 
static auto constexpr min_region_size = UINT64_C (1) << 22U
 

Member Function Documentation

◆ copy()

template<typename Traits , typename Function >
void pstore::storage::copy ( address  addr,
std::size_t  size,
typename Traits::temp_pointer  p,
Function  copier 
) const

This function performs the bulk of the work of creating a "shadow" block when a request spans more than one memory-mapped region (or when PSTORE_ALWAYS_SPANNING is enabled).

It breaks the data into a series of copies (each read or writing as much data as possible) and calls the provided "copier" function to perform the actual copy. This same function is used to copy data from the store into a newly allocated block, and to copy from a contiguous block back to the store.

The template traits argument controls the direction of copy: either copy_from_store_traits or copy_to_store_traits may be used.

Parameters
addrThe store address of the data to be copied.
sizeThe number of bytes to be copied.
pA pointer to a block of memory of at least 'size' bytes.
copierA function that will perform the actual copy. The expected type of the function's arguments are controlled by the 'traits' template argument. The function will be passed 3 arguments:
  • Traits::in_store_pointer: An address lying within the data store.
  • Traits::temp_pointer: A pointer within the memory block given by [p,p+size).
  • std::uint64_t: The number of bytes to be copied.

◆ request_spans_regions()

bool pstore::storage::request_spans_regions ( address const &  addr,
std::size_t  size 
) const
inlinenoexcept

Returns true if the given address range "spans" more than one region.

Note
The PSTORE_ALWAYS_SPANNING configure-time setting can cause this function to always return true.
We expect addr and size to have been checked for sanity by the caller.
Parameters
addrThe start of the address range to be considered.
sizeThe size of the address range to be considered.
Returns
true if the given address range "spans" more than one region.

◆ segment_base()

std::shared_ptr<void const> pstore::storage::segment_base ( address::segment_type const  segment) const
inlinenoexcept

Returns the base address of a segment given its index.

Parameters
segmentThe segment number whose base address it to be returned. The segment number must lie within the memory mapped regions.

◆ update_master_pointers()

void pstore::storage::update_master_pointers ( std::size_t  old_length)

Called to add newly created memory-mapped regions to the segment address table.

This happens when the file is initially opened, and when it is grown by calling allocate().


The documentation for this class was generated from the following files: