Core Library 1.7.0.0 Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.

Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
core_lib::threads::BoundedBuffer< T > Class Template Referencefinal

Class defining a bounded buffer. More...

`#include <BoundedBuffer.h>`

## Public Types
using | container_type = boost::circular_buffer< T >
| Typedef for container type.
using | size_type = typename container_type::size_type
| Typedef for container size type.
using | value_type = typename container_type::value_type
| Typedef for container value type.
using | param_type = typename boost::call_traits< value_type >::param_type
| Typedef for container param type.

## Public Member Functions
| BoundedBuffer (size_type capacity)
| Constructor. More...
| ~BoundedBuffer ()=default
| Default destructor.
| BoundedBuffer (const BoundedBuffer &)=delete
| Copy constructor deleted.
BoundedBuffer & | operator= (const BoundedBuffer &)=delete
| Copy assignment operator deleted.
| BoundedBuffer (BoundedBuffer &&)=delete
| Move constructor deleted.
BoundedBuffer & | operator= (BoundedBuffer &&)=delete
| Move assignment operator deleted.
void | PushFront (param_type item)
| Push new item to the front. More...
void | PopBack (value_type &item)
| Pop item from the back. More...

## Private Member Functions
bool | IsNotEmpty () const
| Test if buffer not empty. More...
bool | IsNotFull () const
| Test if buffer not full. More...

## Private Attributes
std::mutex | m_mutex
| Synchronization mutex.
std::condition_variable | m_notEmptyEvent
| Condition variable to flag not empty.
std::condition_variable | m_notFullEvent
| Condition variable to flag not full.
size_type | m_unreadCount {0}
| Unread count.
container_type | m_container {}
| Circular buffer.

## Detailed Description

### template<typename T>
class core_lib::threads::BoundedBuffer< T >

Class defining a bounded buffer.

This class implements a fully thread-safe bounded circular buffer that blocks the consumer thread when empty and blocks the producer thread when full. It acts like a bounded single producer/single consumer queue.

This code is based on the example given in the boost circular buffer documentation.

## Constructor & Destructor Documentation

## ◆ BoundedBuffer()

template<typename T >

core_lib::threads::BoundedBuffer< T >::BoundedBuffer | ( | size_type | capacity | ) |
| inline explicit

Constructor.

Parameters

  [in] | capacity | - The capacity for the underlying circular buffer.

## Member Function Documentation

## ◆ IsNotEmpty()

template<typename T >

bool core_lib::threads::BoundedBuffer< T >::IsNotEmpty | ( |  | ) | const
| inline private

Test if buffer not empty.

Returns
  True if buffer not empty, false otherwise.

## ◆ IsNotFull()

template<typename T >

bool core_lib::threads::BoundedBuffer< T >::IsNotFull | ( |  | ) | const
| inline private

Test if buffer not full.

Returns
  True if buffer not full, false otherwise.

## ◆ PopBack()

template<typename T >

void core_lib::threads::BoundedBuffer< T >::PopBack | ( | value_type & | item | ) |
| inline

Pop item from the back.

Parameters

  [out] | item | - The item to pop from the back.

This function blocks if the buffer is at capacity.

## ◆ PushFront()

template<typename T >

void core_lib::threads::BoundedBuffer< T >::PushFront | ( | param_type | item | ) |
| inline

Push new item to the front.

Parameters

  [in] | item | - The item to push to the front.

This function blocks if the buffer is at capacity.

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

- D:/Projects/CoreLibrary/Include/Threads/BoundedBuffer.h