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
 
void push_back (T &&item)
 
void append_rows (std::vector< T > &&rows)
 
pop_front () noexcept
 
size_t drain_front (std::vector< T > &out, size_t max_items)
 Move up to max_items rows into a caller-owned batch buffer under one lock.
 
template<typename Callback >
void inspect (Callback &&callback) const
 Invoke callback with a synchronized copy of queued rows.
 
bool is_waitable () const noexcept
 Returns true if a thread is actively pushing items to this deque.
 
void wait ()
 
size_t size () const noexcept
 
void notify_all ()
 Tell listeners that this deque is actively being pushed to.
 
void kill_all ()
 

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; inspect() is the synchronized observation path for tests and diagnostics. Keep inspect() as a local ThreadSafeDeque affordance instead of promoting a generic queue-view type into the parser queue concept.

Definition at line 35 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 37 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 39 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 49 of file thread_safe_deque.hpp.

Member Function Documentation

◆ append_rows()

template<typename T >
void csv::internals::ThreadSafeDeque< T >::append_rows ( std::vector< T > &&  rows)
inline

Definition at line 79 of file thread_safe_deque.hpp.

◆ drain_front()

template<typename T >
size_t csv::internals::ThreadSafeDeque< T >::drain_front ( std::vector< T > &  out,
size_t  max_items 
)
inline

Move up to max_items rows into a caller-owned batch buffer under one lock.

This is the preferred consumer path for chunked reads: it preserves queue semantics while amortizing mutex traffic across many rows. Complete queued batches are moved as contiguous spans; per-row moves only remain when the requested limit splits a batch.

Definition at line 115 of file thread_safe_deque.hpp.

◆ empty()

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

Definition at line 62 of file thread_safe_deque.hpp.

◆ inspect()

template<typename T >
template<typename Callback >
void csv::internals::ThreadSafeDeque< T >::inspect ( Callback &&  callback) const
inline

Invoke callback with a synchronized copy of queued rows.

Intended for tests and diagnostics that need stable indexed observation without exposing unsynchronized random access. The plain vector snapshot is deliberate: callers do not need to know whether the underlying queue is batch-backed, and RowDequeLike should not grow a custom inspection-view abstraction.

Definition at line 141 of file thread_safe_deque.hpp.

◆ is_waitable()

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

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

Definition at line 162 of file thread_safe_deque.hpp.

◆ kill_all()

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

Definition at line 188 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 182 of file thread_safe_deque.hpp.

◆ pop_front()

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

Definition at line 94 of file thread_safe_deque.hpp.

◆ push_back()

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

Definition at line 66 of file thread_safe_deque.hpp.

◆ size()

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

Definition at line 176 of file thread_safe_deque.hpp.

◆ wait()

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

Definition at line 166 of file thread_safe_deque.hpp.


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