KiCad PCB EDA Suite
SYNC_QUEUE< T > Class Template Reference

Synchronized, locking queue. More...

#include <sync_queue.h>

Public Member Functions

 SYNC_QUEUE ()
 
void push (T const &aValue)
 Push a value onto the queue. More...
 
void move_push (T &&aValue)
 Move a value onto the queue. More...
 
bool pop (T &aReceiver)
 Pop a value off the queue into the provided variable. More...
 
bool empty () const
 Return true iff the queue is empty. More...
 
size_t size () const
 Return the size of the queue. More...
 
void clear ()
 Clear the queue. More...
 

Private Types

typedef std::lock_guard< std::mutex > GUARD
 

Private Attributes

std::queue< T > m_queue
 
std::mutex m_mutex
 

Detailed Description

template<typename T>
class SYNC_QUEUE< T >

Synchronized, locking queue.

Safe for multiple producer/multiple consumer environments with nontrivial data (though bear in mind data needs to be copied in and out).

Definition at line 30 of file sync_queue.h.

Member Typedef Documentation

template<typename T>
typedef std::lock_guard<std::mutex> SYNC_QUEUE< T >::GUARD
private

Definition at line 32 of file sync_queue.h.

Constructor & Destructor Documentation

template<typename T>
SYNC_QUEUE< T >::SYNC_QUEUE ( )
inline

Definition at line 38 of file sync_queue.h.

39  {
40  }

Member Function Documentation

template<typename T>
void SYNC_QUEUE< T >::clear ( )
inline

Clear the queue.

Definition at line 103 of file sync_queue.h.

Referenced by FOOTPRINT_LIST_IMPL::JoinWorkers(), and FOOTPRINT_LIST_IMPL::StartWorkers().

104  {
105  GUARD guard( m_mutex );
106 
107  while( !m_queue.empty() )
108  {
109  m_queue.pop();
110  }
111  }
std::mutex m_mutex
Definition: sync_queue.h:35
std::lock_guard< std::mutex > GUARD
Definition: sync_queue.h:32
std::queue< T > m_queue
Definition: sync_queue.h:34
template<typename T>
bool SYNC_QUEUE< T >::empty ( ) const
inline

Return true iff the queue is empty.

Definition at line 85 of file sync_queue.h.

Referenced by FOOTPRINT_LIST_IMPL::JoinWorkers().

86  {
87  GUARD guard( m_mutex );
88  return m_queue.empty();
89  }
std::mutex m_mutex
Definition: sync_queue.h:35
std::lock_guard< std::mutex > GUARD
Definition: sync_queue.h:32
std::queue< T > m_queue
Definition: sync_queue.h:34
template<typename T>
void SYNC_QUEUE< T >::move_push ( T &&  aValue)
inline

Move a value onto the queue.

Useful for e.g. unique_ptr.

Definition at line 54 of file sync_queue.h.

Referenced by FOOTPRINT_LIST_IMPL::CatchErrors(), and FOOTPRINT_LIST_IMPL::JoinWorkers().

55  {
56  GUARD guard( m_mutex );
57  m_queue.push( std::move( aValue ) );
58  }
std::mutex m_mutex
Definition: sync_queue.h:35
std::lock_guard< std::mutex > GUARD
Definition: sync_queue.h:32
std::queue< T > m_queue
Definition: sync_queue.h:34
template<typename T>
bool SYNC_QUEUE< T >::pop ( T &  aReceiver)
inline

Pop a value off the queue into the provided variable.

If the queue is empty, the variable is not touched.

Returns
true iff a value was popped.

Definition at line 66 of file sync_queue.h.

Referenced by FOOTPRINT_LIST_IMPL::JoinWorkers(), FOOTPRINT_LIST_IMPL::loader_job(), and FOOTPRINT_LIST::PopError().

67  {
68  GUARD guard( m_mutex );
69 
70  if( m_queue.empty() )
71  {
72  return false;
73  }
74  else
75  {
76  aReceiver = std::move( m_queue.front() );
77  m_queue.pop();
78  return true;
79  }
80  }
std::mutex m_mutex
Definition: sync_queue.h:35
std::lock_guard< std::mutex > GUARD
Definition: sync_queue.h:32
std::queue< T > m_queue
Definition: sync_queue.h:34
template<typename T>
void SYNC_QUEUE< T >::push ( T const &  aValue)
inline

Push a value onto the queue.

Definition at line 45 of file sync_queue.h.

Referenced by FOOTPRINT_LIST_IMPL::loader_job(), and FOOTPRINT_LIST_IMPL::StartWorkers().

46  {
47  GUARD guard( m_mutex );
48  m_queue.push( aValue );
49  }
std::mutex m_mutex
Definition: sync_queue.h:35
std::lock_guard< std::mutex > GUARD
Definition: sync_queue.h:32
std::queue< T > m_queue
Definition: sync_queue.h:34
template<typename T>
size_t SYNC_QUEUE< T >::size ( ) const
inline

Return the size of the queue.

Definition at line 94 of file sync_queue.h.

Referenced by FOOTPRINT_LIST::GetErrorCount(), and FOOTPRINT_LIST_IMPL::StartWorkers().

95  {
96  GUARD guard( m_mutex );
97  return m_queue.size();
98  }
std::mutex m_mutex
Definition: sync_queue.h:35
std::lock_guard< std::mutex > GUARD
Definition: sync_queue.h:32
std::queue< T > m_queue
Definition: sync_queue.h:34

Member Data Documentation

template<typename T>
std::mutex SYNC_QUEUE< T >::m_mutex
mutableprivate

Definition at line 35 of file sync_queue.h.

template<typename T>
std::queue<T> SYNC_QUEUE< T >::m_queue
private

Definition at line 34 of file sync_queue.h.


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