join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicProducer< Policy > Class Template Reference

shared memory producer. More...

#include <shared.hpp>

Inheritance diagram for join::BasicProducer< Policy >:
Collaboration diagram for join::BasicProducer< Policy >:

Public Member Functions

 BasicProducer (const std::string &name, uint64_t elementSize=1472, uint64_t capacity=144)
 create instance.
 
 BasicProducer (const BasicProducer &other)=delete
 copy constructor.
 
BasicProduceroperator= (const BasicProducer &other)=delete
 copy assignment operator.
 
 ~BasicProducer ()=default
 destroy the instance.
 
int tryPush (const void *element) noexcept
 try to push element into ring buffer.
 
int push (const void *element) noexcept
 push element into the ring buffer.
 
template<class Rep , class Period >
int timedPush (const void *element, std::chrono::duration< Rep, Period > timeout) noexcept
 try to push element into the ring buffer until timeout expire.
 
uint64_t available () const noexcept
 get the number of available slots for writing.
 
bool full () const noexcept
 check if the ring buffer is full.
 
- Public Member Functions inherited from join::BasicQueue< Policy >
 BasicQueue (const std::string &name, uint64_t elementSize=1472, uint64_t capacity=144)
 create instance.
 
 BasicQueue (const BasicQueue &other)=delete
 copy constructor.
 
BasicQueueoperator= (const BasicQueue &other)=delete
 copy assignment operator.
 
virtual ~BasicQueue ()
 destroy the instance.
 
int open () override
 open or create the shared memory segment.
 
void close () noexcept override
 close the shared memory segment.
 
const void * get (uint64_t offset=0) const override
 get a const pointer to the shared memory data region at a given offset.
 
void * get (uint64_t offset=0) override
 get a pointer to the shared memory data region at a given offset.
 
uint64_t elementSize () const noexcept
 get the element size of the shared memory region.
 
uint64_t capacity () const noexcept
 get the capacity of the shared memory region.
 
uint64_t size () const noexcept override
 get the size of the shared memory region.
 
- Public Member Functions inherited from join::SharedMemory
 SharedMemory (const std::string &name, uint64_t size)
 create instance.
 
virtual ~SharedMemory ()
 destroy the instance.
 
bool opened () const noexcept
 check if shared memory is opened.
 

Additional Inherited Members

- Static Public Member Functions inherited from join::SharedMemory
static int unlink (const std::string &name) noexcept
 destroy synchronization primitives and unlink the shared memory segment.
 
- Protected Attributes inherited from join::BasicQueue< Policy >
Policy _policy
 shared memory segment policy.
 
uint64_t _elementSize = 0
 shared memory segment element size.
 
uint64_t _capacity = 0
 shared memory segment capacity.
 
uint64_t _totalSize = 0
 total shared memory size.
 
uint64_t _userSize = 0
 user shared memory size.
 
SharedSegment_segment = nullptr
 shared memory segment.
 
- Protected Attributes inherited from join::SharedMemory
std::string _name
 shared memory name.
 
uint64_t _size = 0
 shared memory size.
 
void * _ptr = nullptr
 pointer to mapped shared memory.
 
int _fd = -1
 shared memory file descriptor.
 

Detailed Description

template<typename Policy>
class join::BasicProducer< Policy >

shared memory producer.

Constructor & Destructor Documentation

◆ BasicProducer() [1/2]

template<typename Policy >
join::BasicProducer< Policy >::BasicProducer ( const std::string & name,
uint64_t elementSize = 1472,
uint64_t capacity = 144 )
inline

create instance.

Parameters
nameshared memory segment name.
elementSizeshared memory segment element size.
capacityshared memory segment capacity.

◆ BasicProducer() [2/2]

template<typename Policy >
join::BasicProducer< Policy >::BasicProducer ( const BasicProducer< Policy > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ ~BasicProducer()

template<typename Policy >
join::BasicProducer< Policy >::~BasicProducer ( )
default

destroy the instance.

Member Function Documentation

◆ available()

template<typename Policy >
uint64_t join::BasicProducer< Policy >::available ( ) const
inlinenoexcept

get the number of available slots for writing.

Returns
number of slots available in the ring buffer.

◆ full()

template<typename Policy >
bool join::BasicProducer< Policy >::full ( ) const
inlinenoexcept

check if the ring buffer is full.

Returns
true if full, false otherwise.

◆ operator=()

template<typename Policy >
BasicProducer & join::BasicProducer< Policy >::operator= ( const BasicProducer< Policy > & other)
delete

copy assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ push()

template<typename Policy >
int join::BasicProducer< Policy >::push ( const void * element)
inlinenoexcept

push element into the ring buffer.

Parameters
elementpointer to element to push.
Returns
0 on success, -1 otherwise.

◆ timedPush()

template<typename Policy >
template<class Rep , class Period >
int join::BasicProducer< Policy >::timedPush ( const void * element,
std::chrono::duration< Rep, Period > timeout )
inlinenoexcept

try to push element into the ring buffer until timeout expire.

Parameters
elementpointer to element to push.
timeouttimeout.
Returns
0 on success, -1 otherwise.

◆ tryPush()

template<typename Policy >
int join::BasicProducer< Policy >::tryPush ( const void * element)
inlinenoexcept

try to push element into ring buffer.

Parameters
elementpointer to element to push.
Returns
0 on success, -1 otherwise.

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