Vince's CSV Parser
Loading...
Searching...
No Matches
csv::internals::ThreadSafeDeque< T > Class Template Reference

A std::deque wrapper which allows multiple read and write threads to concurrently access it along with providing read threads the ability to wait for the deque to become populated. More...

#include <thread_safe_deque.hpp>

Public Member Functions

 ThreadSafeDeque (size_t notify_size=100)
 
 ThreadSafeDeque (const ThreadSafeDeque &other)
 
 ThreadSafeDeque (const std::deque< T > &source)
 
bool empty () const noexcept
 
Tfront () noexcept
 
Toperator[] (size_t n)
 NOTE: operator[] is not synchronized.
 
void push_back (T &&item)
 
T pop_front () noexcept
 
constexpr bool is_waitable () const noexcept
 Returns true if a thread is actively pushing items to this deque.
 
void wait ()
 Wait for an item to become available.
 
size_t size () const noexcept
 
std::deque< T >::iterator begin () noexcept
 
std::deque< T >::iterator end () noexcept
 
void notify_all ()
 Tell listeners that this deque is actively being pushed to.
 
void kill_all ()
 Tell all listeners to stop.
 

Detailed Description

template<typename T>
class csv::internals::ThreadSafeDeque< T >

A std::deque wrapper which allows multiple read and write threads to concurrently access it along with providing read threads the ability to wait for the deque to become populated.

Concurrency strategy: writer-side mutations (push_back/pop_front) are locked; hot-path flags (empty/is_waitable) are atomic; operator[] and iterators are not synchronized and must not run concurrently with writers.

Definition at line 25 of file thread_safe_deque.hpp.

Constructor & Destructor Documentation

◆ ThreadSafeDeque() [1/3]

template<typename T >
csv::internals::ThreadSafeDeque< T >::ThreadSafeDeque ( size_t  notify_size = 100)
inline

Definition at line 27 of file thread_safe_deque.hpp.

◆ ThreadSafeDeque() [2/3]

template<typename T >
csv::internals::ThreadSafeDeque< T >::ThreadSafeDeque ( const ThreadSafeDeque< T > &  other)
inline

Definition at line 28 of file thread_safe_deque.hpp.

◆ ThreadSafeDeque() [3/3]

template<typename T >
csv::internals::ThreadSafeDeque< T >::ThreadSafeDeque ( const std::deque< T > &  source)
inline

Definition at line 34 of file thread_safe_deque.hpp.

Member Function Documentation

◆ begin()

template<typename T >
std::deque< T >::iterator csv::internals::ThreadSafeDeque< T >::begin ( )
inlinenoexcept

Definition at line 99 of file thread_safe_deque.hpp.

◆ empty()

template<typename T >
bool csv::internals::ThreadSafeDeque< T >::empty ( ) const
inlinenoexcept

Definition at line 39 of file thread_safe_deque.hpp.

◆ end()

template<typename T >
std::deque< T >::iterator csv::internals::ThreadSafeDeque< T >::end ( )
inlinenoexcept

Definition at line 103 of file thread_safe_deque.hpp.

◆ front()

template<typename T >
T & csv::internals::ThreadSafeDeque< T >::front ( )
inlinenoexcept

Definition at line 43 of file thread_safe_deque.hpp.

◆ is_waitable()

template<typename T >
constexpr bool csv::internals::ThreadSafeDeque< T >::is_waitable ( ) const
inlineconstexprnoexcept

Returns true if a thread is actively pushing items to this deque.

Definition at line 81 of file thread_safe_deque.hpp.

◆ kill_all()

template<typename T >
void csv::internals::ThreadSafeDeque< T >::kill_all ( )
inline

Tell all listeners to stop.

Definition at line 114 of file thread_safe_deque.hpp.

◆ notify_all()

template<typename T >
void csv::internals::ThreadSafeDeque< T >::notify_all ( )
inline

Tell listeners that this deque is actively being pushed to.

Definition at line 108 of file thread_safe_deque.hpp.

◆ operator[]()

template<typename T >
T & csv::internals::ThreadSafeDeque< T >::operator[] ( size_t  n)
inline

NOTE: operator[] is not synchronized.

Only call when no concurrent push_back/pop_front can occur. std::deque can reallocate its internal map on push_back, which makes concurrent operator[] access undefined behavior.

Definition at line 53 of file thread_safe_deque.hpp.

◆ pop_front()

template<typename T >
T csv::internals::ThreadSafeDeque< T >::pop_front ( )
inlinenoexcept

Definition at line 67 of file thread_safe_deque.hpp.

◆ push_back()

template<typename T >
void csv::internals::ThreadSafeDeque< T >::push_back ( T &&  item)
inline

Definition at line 57 of file thread_safe_deque.hpp.

◆ size()

template<typename T >
size_t csv::internals::ThreadSafeDeque< T >::size ( ) const
inlinenoexcept

Definition at line 94 of file thread_safe_deque.hpp.

◆ wait()

template<typename T >
void csv::internals::ThreadSafeDeque< T >::wait ( )
inline

Wait for an item to become available.

Definition at line 84 of file thread_safe_deque.hpp.


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