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 if the queue into the provided variable. More...
 
bool empty () const
 Return true if 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 31 of file sync_queue.h.

Member Typedef Documentation

◆ GUARD

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

Definition at line 111 of file sync_queue.h.

Constructor & Destructor Documentation

◆ SYNC_QUEUE()

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

Definition at line 34 of file sync_queue.h.

35 {
36 }

Member Function Documentation

◆ clear()

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

Clear the queue.

Definition at line 100 of file sync_queue.h.

101 {
102 GUARD guard( m_mutex );
103
104 while( !m_queue.empty() )
105 {
106 m_queue.pop();
107 }
108 }
std::mutex m_mutex
Definition: sync_queue.h:114
std::lock_guard< std::mutex > GUARD
Definition: sync_queue.h:111
std::queue< T > m_queue
Definition: sync_queue.h:113

References SYNC_QUEUE< T >::m_mutex, and SYNC_QUEUE< T >::m_queue.

Referenced by FOOTPRINT_LIST_IMPL::ReadFootprintFiles().

◆ empty()

template<typename T >
bool SYNC_QUEUE< T >::empty ( ) const
inline

Return true if the queue is empty.

Definition at line 82 of file sync_queue.h.

83 {
84 GUARD guard( m_mutex );
85 return m_queue.empty();
86 }

References SYNC_QUEUE< T >::m_mutex, and SYNC_QUEUE< T >::m_queue.

Referenced by FOOTPRINT_LIST_IMPL::ReadFootprintFiles(), and PCM_TASK_MANAGER::RunQueue().

◆ move_push()

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 50 of file sync_queue.h.

51 {
52 GUARD guard( m_mutex );
53 m_queue.push( std::move( aValue ) );
54 }

References SYNC_QUEUE< T >::m_mutex, and SYNC_QUEUE< T >::m_queue.

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

◆ pop()

template<typename T >
bool SYNC_QUEUE< T >::pop ( T &  aReceiver)
inline

Pop a value if the queue into the provided variable.

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

Returns
true if a value was popped.

Definition at line 63 of file sync_queue.h.

64 {
65 GUARD guard( m_mutex );
66
67 if( m_queue.empty() )
68 {
69 return false;
70 }
71 else
72 {
73 aReceiver = std::move( m_queue.front() );
74 m_queue.pop();
75 return true;
76 }
77 }

References SYNC_QUEUE< T >::m_mutex, and SYNC_QUEUE< T >::m_queue.

Referenced by FOOTPRINT_LIST_IMPL::loadFootprints(), FOOTPRINT_LIST_IMPL::loadLibs(), and PCM_TASK_MANAGER::RunQueue().

◆ push()

template<typename T >
void SYNC_QUEUE< T >::push ( T const &  aValue)
inline

Push a value onto the queue.

Definition at line 41 of file sync_queue.h.

42 {
43 GUARD guard( m_mutex );
44 m_queue.push( aValue );
45 }

References SYNC_QUEUE< T >::m_mutex, and SYNC_QUEUE< T >::m_queue.

Referenced by PCM_TASK_MANAGER::DownloadAndInstall(), FOOTPRINT_LIST_IMPL::loadLibs(), FOOTPRINT_LIST_IMPL::ReadFootprintFiles(), and PCM_TASK_MANAGER::Uninstall().

◆ size()

template<typename T >
size_t SYNC_QUEUE< T >::size ( ) const
inline

Return the size of the queue.

Definition at line 91 of file sync_queue.h.

92 {
93 GUARD guard( m_mutex );
94 return m_queue.size();
95 }

References SYNC_QUEUE< T >::m_mutex, and SYNC_QUEUE< T >::m_queue.

Referenced by FOOTPRINT_LIST_IMPL::loadFootprints(), FOOTPRINT_LIST_IMPL::loadLibs(), FOOTPRINT_LIST_IMPL::ReadFootprintFiles(), and PCM_TASK_MANAGER::RunQueue().

Member Data Documentation

◆ m_mutex

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

◆ m_queue

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

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