join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::ShmMem Class Reference

posix shared memory provider. More...

#include <memory.hpp>

Public Types

template<size_t Count, size_t... Sizes>
using Allocator = BasicArena<ShmMem, Count, Sizes...>
 
using Spsc = SyncBinding<ShmMem, ::join::Spsc>
 
using Mpsc = SyncBinding<ShmMem, ::join::Mpsc>
 
using Mpmc = SyncBinding<ShmMem, ::join::Mpmc>
 

Public Member Functions

 ShmMem (uint64_t size, const std::string &name)
 creates or opens a named shared memory segment.
 
 ShmMem (const ShmMem &other)=delete
 copy constructor.
 
ShmMemoperator= (const ShmMem &other)=delete
 copy assignment operator.
 
 ShmMem (ShmMem &&other) noexcept
 move constructor.
 
ShmMemoperator= (ShmMem &&other) noexcept
 move assignment operator.
 
 ~ShmMem () noexcept
 unmaps the memory and closes the file descriptor.
 
const void * get (uint64_t offset=0) const
 get a const pointer to the shared memory at a given offset.
 
void * get (uint64_t offset=0)
 get a pointer to the shared memory at a given offset.
 
int mbind (int numa) const noexcept
 bind memory to a NUMA node.
 
int mlock () const noexcept
 lock memory in RAM.
 

Static Public Member Functions

static int unlink (const std::string &name) noexcept
 destroy synchronization primitives and unlink the shared memory segment.
 

Detailed Description

posix shared memory provider.

Member Typedef Documentation

◆ Allocator

template<size_t Count, size_t... Sizes>
using join::ShmMem::Allocator = BasicArena<ShmMem, Count, Sizes...>

◆ Mpmc

◆ Mpsc

◆ Spsc

Constructor & Destructor Documentation

◆ ShmMem() [1/3]

join::ShmMem::ShmMem ( uint64_t size,
const std::string & name )
inlineexplicit

creates or opens a named shared memory segment.

Parameters
sizeshared memory size in bytes.
nameshared memory unique name.
Exceptions
std::system_errorif mmap fails.

◆ ShmMem() [2/3]

join::ShmMem::ShmMem ( const ShmMem & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ ShmMem() [3/3]

join::ShmMem::ShmMem ( ShmMem && other)
inlinenoexcept

move constructor.

Parameters
otherother object to move.

◆ ~ShmMem()

join::ShmMem::~ShmMem ( )
inlinenoexcept

unmaps the memory and closes the file descriptor.

Member Function Documentation

◆ get() [1/2]

void * join::ShmMem::get ( uint64_t offset = 0)
inline

get a pointer to the shared memory at a given offset.

Parameters
offsetbyte offset from the start of the shared memory.
Returns
pointer to the mapped memory at the specified offset, or nullptr if not opened.
Exceptions
std::runtime_errorif memory is not mapped.
std::out_of_rangeif offset is out of bounds.

◆ get() [2/2]

const void * join::ShmMem::get ( uint64_t offset = 0) const
inline

get a const pointer to the shared memory at a given offset.

Parameters
offsetbyte offset from the start of the shared memory.
Returns
pointer to the mapped memory at the specified offset, or nullptr if not opened.
Exceptions
std::runtime_errorif memory is not mapped.
std::out_of_rangeif offset is out of bounds.

◆ mbind()

int join::ShmMem::mbind ( int numa) const
inlinenoexcept

bind memory to a NUMA node.

Parameters
numaNUMA node ID.
Returns
0 on success, -1 on failure.

◆ mlock()

int join::ShmMem::mlock ( ) const
inlinenoexcept

lock memory in RAM.

Returns
0 on success, -1 on failure.

◆ operator=() [1/2]

ShmMem & join::ShmMem::operator= ( const ShmMem & other)
delete

copy assignment operator.

Parameters
otherother object to copy.
Returns
this.

◆ operator=() [2/2]

ShmMem & join::ShmMem::operator= ( ShmMem && other)
inlinenoexcept

move assignment operator.

Parameters
otherother object to move.
Returns
this.

◆ unlink()

static int join::ShmMem::unlink ( const std::string & name)
inlinestaticnoexcept

destroy synchronization primitives and unlink the shared memory segment.

Parameters
nameshared memory segment name.
Returns
0 on success, -1 on failure.

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