Ensō 0.4.6
Software API reference
Loading...
Searching...
No Matches
enso::Queue< T, Subclass > Class Template Reference

Queue parent class. More...

#include <queue.h>

Classes

struct  Element
 

Public Member Functions

 Queue (Queue &&other)=default
 
Queueoperator= (Queue &&other)=default
 
Elementbuf_addr () const noexcept
 Returns the address of the internal buffer.
 
size_t size () const noexcept
 Returns the size of the internal buffer.
 
uint32_t capacity () const noexcept
 Returns the capacity of the queue.
 

Static Public Member Functions

static std::unique_ptr< Subclass > Create (const std::string &queue_name, size_t size=0, bool join_if_exists=true, std::string huge_page_prefix="") noexcept
 Factory method to create a Queue object.
 

Static Public Attributes

static constexpr size_t kElementMetaSize = sizeof(T) + 8
 
static constexpr size_t kElementPadding
 

Protected Member Functions

 Queue (const std::string &queue_name, size_t size, const std::string &huge_page_prefix) noexcept
 
int Init (bool join_if_exists) noexcept
 Initializes the Queue object.
 
bool created_queue () const noexcept
 
uint32_t index_mask () const noexcept
 

Detailed Description

template<typename T, typename Subclass>
class enso::Queue< T, Subclass >

Queue parent class.

Use this queue to communicate between different threads. It should be instantiated using either the QueueConsumer or QueueProducer classes through the Create method.

Example: // Producer. std::unique_ptr<QueueProducer<int>> queue_producer = QueueProducer<int>::Create("queue_name");

// Consumer. std::unique_ptr<QueueConsumer<int>> queue_consumer = QueueConsumer<int>::Create("queue_name");

queue_producer->Push(42);

int data = queue_consumer->Pop().value_or(-1); std::cout << data << std::endl; // Should print 42.

data = queue_consumer->Pop().value_or(-1); std::cout << data << std::endl; // Should print -1.

Definition at line 98 of file queue.h.

Constructor & Destructor Documentation

◆ ~Queue()

template<typename T , typename Subclass >
enso::Queue< T, Subclass >::~Queue ( )
inlinenoexcept

Definition at line 115 of file queue.h.

◆ Queue()

template<typename T , typename Subclass >
enso::Queue< T, Subclass >::Queue ( const std::string &  queue_name,
size_t  size,
const std::string &  huge_page_prefix 
)
inlineexplicitprotectednoexcept

Definition at line 184 of file queue.h.

Member Function Documentation

◆ buf_addr()

template<typename T , typename Subclass >
Element * enso::Queue< T, Subclass >::buf_addr ( ) const
inlinenoexcept

Returns the address of the internal buffer.

Returns
The address of the internal buffer.

Definition at line 166 of file queue.h.

◆ capacity()

template<typename T , typename Subclass >
uint32_t enso::Queue< T, Subclass >::capacity ( ) const
inlinenoexcept

Returns the capacity of the queue.

Returns
The capacity of the queue in number of elements.

Definition at line 178 of file queue.h.

◆ Create()

template<typename T , typename Subclass >
static std::unique_ptr< Subclass > enso::Queue< T, Subclass >::Create ( const std::string &  queue_name,
size_t  size = 0,
bool  join_if_exists = true,
std::string  huge_page_prefix = "" 
)
inlinestaticnoexcept

Factory method to create a Queue object.

Parameters
queue_nameGlobal queue name.
sizeSize of the queue (in bytes). If zero (default), the size will be inferred if the queue already exists and will be set to kBufPageSize otherwise.
join_if_existsIf true (default), the queue will be joined if it already exists. If false, the creation will fail if the queue already exists.
huge_page_prefixPrefix to use when creating the shared memory file. If empty (default), the default prefix will be used.
Returns
A unique pointer to the object or nullptr if the creation fails.

Definition at line 141 of file queue.h.

◆ created_queue()

template<typename T , typename Subclass >
bool enso::Queue< T, Subclass >::created_queue ( ) const
inlineprotectednoexcept

Definition at line 279 of file queue.h.

◆ index_mask()

template<typename T , typename Subclass >
uint32_t enso::Queue< T, Subclass >::index_mask ( ) const
inlineprotectednoexcept

Definition at line 281 of file queue.h.

◆ Init()

template<typename T , typename Subclass >
int enso::Queue< T, Subclass >::Init ( bool  join_if_exists)
inlineprotectednoexcept

Initializes the Queue object.

Parameters
join_if_existsIf true, the queue will be joined if it already exists. If false, the creation will fail if the queue already exists.
Returns
0 on success and a non-zero error code on failure.

Definition at line 198 of file queue.h.

◆ size()

template<typename T , typename Subclass >
size_t enso::Queue< T, Subclass >::size ( ) const
inlinenoexcept

Returns the size of the internal buffer.

Returns
The size of the internal buffer.

Definition at line 172 of file queue.h.

Member Data Documentation

◆ kElementMetaSize

template<typename T , typename Subclass >
constexpr size_t enso::Queue< T, Subclass >::kElementMetaSize = sizeof(T) + 8
staticconstexpr

Definition at line 100 of file queue.h.

◆ kElementPadding

template<typename T , typename Subclass >
constexpr size_t enso::Queue< T, Subclass >::kElementPadding
staticconstexpr
Initial value:
=
align_cache_power_two(kElementMetaSize) - kElementMetaSize

Definition at line 101 of file queue.h.


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