bmv2
Designing your own switch target with bmv2
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | List of all members
bm::Queue< T > Class Template Reference

Public Types

enum  WriteBehavior { WriteBlock, WriteReturn }
 Implementation behavior when an item is pushed to a full queue. More...
 
enum  ReadBehavior { ReadBlock, ReadReturn }
 Implementation behavior when an element is popped from an empty queue. More...
 

Public Member Functions

 Queue (size_t capacity, WriteBehavior wb=WriteBlock, ReadBehavior rb=ReadBlock)
 Constructs a queue with specified capacity and read / write behaviors. More...
 
void push_front (const T &item)
 Makes a copy of item and pushes it to the front of the queue. More...
 
void push_front (T &&item)
 Moves item to the front of the queue. More...
 
void pop_back (T *pItem)
 Pops an element from the back of the queue: moves the element to *pItem. More...
 
size_t size () const
 Get queue occupancy. More...
 
void set_capacity (const size_t c)
 Change the capacity of the queue. More...
 
 Queue (const Queue &)=delete
 Deleted copy constructor. More...
 
Queueoperator= (const Queue &)=delete
 Deleted copy assignment operator. More...
 
 Queue (Queue &&)=delete
 Deleted move constructor (class includes mutex) More...
 
Queue && operator= (Queue &&)=delete
 Deleted move assignment operator (class includes mutex) More...
 

Detailed Description

template<class T>
class bm::Queue< T >

A utility queueing class made available to all targets. It could be used -for example- to queue packets between an ingress thread and an egress thread. This is a very simple class, which does not implement anything fancy (e.g. rate limiting, priority queueing, fair scheduling, ...) but can be used as a base class to build something more advanced. Queue includes a mutex and is thread-safe.

Member Enumeration Documentation

◆ ReadBehavior

template<class T >
enum bm::Queue::ReadBehavior

Implementation behavior when an element is popped from an empty queue.

Enumerator
ReadBlock 

block and wait until the queue becomes non-empty

ReadReturn 

not implemented yet

◆ WriteBehavior

template<class T >
enum bm::Queue::WriteBehavior

Implementation behavior when an item is pushed to a full queue.

Enumerator
WriteBlock 

block and wait until a slot is available

WriteReturn 

return immediately

Constructor & Destructor Documentation

◆ Queue() [1/3]

template<class T >
bm::Queue< T >::Queue ( size_t  capacity,
WriteBehavior  wb = WriteBlock,
ReadBehavior  rb = ReadBlock 
)
inline

Constructs a queue with specified capacity and read / write behaviors.

◆ Queue() [2/3]

template<class T >
bm::Queue< T >::Queue ( const Queue< T > &  )
delete

Deleted copy constructor.

◆ Queue() [3/3]

template<class T >
bm::Queue< T >::Queue ( Queue< T > &&  )
delete

Deleted move constructor (class includes mutex)

Member Function Documentation

◆ operator=() [1/2]

template<class T >
Queue& bm::Queue< T >::operator= ( const Queue< T > &  )
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

template<class T >
Queue&& bm::Queue< T >::operator= ( Queue< T > &&  )
delete

Deleted move assignment operator (class includes mutex)

◆ pop_back()

template<class T >
void bm::Queue< T >::pop_back ( T *  pItem)
inline

Pops an element from the back of the queue: moves the element to *pItem.

◆ push_front() [1/2]

template<class T >
void bm::Queue< T >::push_front ( const T &  item)
inline

Makes a copy of item and pushes it to the front of the queue.

◆ push_front() [2/2]

template<class T >
void bm::Queue< T >::push_front ( T &&  item)
inline

Moves item to the front of the queue.

◆ set_capacity()

template<class T >
void bm::Queue< T >::set_capacity ( const size_t  c)
inline

Change the capacity of the queue.

◆ size()

template<class T >
size_t bm::Queue< T >::size ( ) const
inline

Get queue occupancy.


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