Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::Channel< T > Class Template Reference

#include <src/libslic3r/Channel.hpp>

+ Inheritance diagram for Slic3r::Channel< T >:
+ Collaboration diagram for Slic3r::Channel< T >:

Classes

class  Unlocker
 

Public Types

using UniqueLock = std::unique_lock< std::mutex >
 
using Queue = std::deque< T >
 
using LockedConstPtr = std::unique_ptr< const Queue, Unlocker< const Queue > >
 
using LockedPtr = std::unique_ptr< Queue, Unlocker< Queue > >
 

Public Member Functions

 Channel ()
 
 ~Channel ()
 
void push (const T &item, bool silent=false)
 
void push (T &&item, bool silent=false)
 
pop ()
 
boost::optional< T > try_pop ()
 
size_t size_hint () const noexcept
 
LockedConstPtr lock_read () const
 
LockedPtr lock_rw ()
 

Private Attributes

Queue m_queue
 
std::mutex m_mutex
 
std::condition_variable m_condition
 

Detailed Description

template<class T>
class Slic3r::Channel< T >

Member Typedef Documentation

◆ LockedConstPtr

template<class T >
using Slic3r::Channel< T >::LockedConstPtr = std::unique_ptr<const Queue, Unlocker<const Queue> >

◆ LockedPtr

template<class T >
using Slic3r::Channel< T >::LockedPtr = std::unique_ptr<Queue, Unlocker<Queue> >

◆ Queue

template<class T >
using Slic3r::Channel< T >::Queue = std::deque<T>

◆ UniqueLock

template<class T >
using Slic3r::Channel< T >::UniqueLock = std::unique_lock<std::mutex>

Constructor & Destructor Documentation

◆ Channel()

template<class T >
Slic3r::Channel< T >::Channel ( )
inline
38{}

◆ ~Channel()

template<class T >
Slic3r::Channel< T >::~Channel ( )
inline
39{}

Member Function Documentation

◆ lock_read()

template<class T >
LockedConstPtr Slic3r::Channel< T >::lock_read ( ) const
inline
84 {
85 return LockedConstPtr(&m_queue, Unlocker<const Queue>(UniqueLock(m_mutex)));
86 }
std::mutex m_mutex
Definition Channel.hpp:94
std::unique_ptr< const Queue, Unlocker< const Queue > > LockedConstPtr
Definition Channel.hpp:35
std::unique_lock< std::mutex > UniqueLock
Definition Channel.hpp:18
Queue m_queue
Definition Channel.hpp:93

References Slic3r::Channel< T >::m_mutex, and Slic3r::Channel< T >::m_queue.

◆ lock_rw()

template<class T >
LockedPtr Slic3r::Channel< T >::lock_rw ( )
inline
89 {
90 return LockedPtr(&m_queue, Unlocker<Queue>(UniqueLock(m_mutex)));
91 }
std::unique_ptr< Queue, Unlocker< Queue > > LockedPtr
Definition Channel.hpp:36

References Slic3r::Channel< T >::m_mutex, and Slic3r::Channel< T >::m_queue.

◆ pop()

template<class T >
T Slic3r::Channel< T >::pop ( )
inline
60 {
62 m_condition.wait(lock, [this]() { return !m_queue.empty(); });
63 auto item = std::move(m_queue.front());
64 m_queue.pop_front();
65 return item;
66 }
std::condition_variable m_condition
Definition Channel.hpp:95

References Slic3r::Channel< T >::m_condition, Slic3r::Channel< T >::m_mutex, and Slic3r::Channel< T >::m_queue.

◆ push() [1/2]

template<class T >
void Slic3r::Channel< T >::push ( const T &  item,
bool  silent = false 
)
inline
42 {
43 {
45 m_queue.push_back(item);
46 }
47 if (! silent) { m_condition.notify_one(); }
48 }

References Slic3r::Channel< T >::m_condition, Slic3r::Channel< T >::m_mutex, and Slic3r::Channel< T >::m_queue.

◆ push() [2/2]

template<class T >
void Slic3r::Channel< T >::push ( T &&  item,
bool  silent = false 
)
inline
51 {
52 {
54 m_queue.push_back(std::forward<T>(item));
55 }
56 if (! silent) { m_condition.notify_one(); }
57 }

References Slic3r::Channel< T >::m_condition, Slic3r::Channel< T >::m_mutex, and Slic3r::Channel< T >::m_queue.

◆ size_hint()

template<class T >
size_t Slic3r::Channel< T >::size_hint ( ) const
inlinenoexcept
81{ return m_queue.size(); }

References Slic3r::Channel< T >::m_queue.

◆ try_pop()

template<class T >
boost::optional< T > Slic3r::Channel< T >::try_pop ( )
inline
69 {
71 if (m_queue.empty()) {
72 return boost::none;
73 } else {
74 auto item = std::move(m_queue.front());
75 m_queue.pop();
76 return item;
77 }
78 }

References Slic3r::Channel< T >::m_mutex, and Slic3r::Channel< T >::m_queue.

Member Data Documentation

◆ m_condition

template<class T >
std::condition_variable Slic3r::Channel< T >::m_condition
private

◆ m_mutex

◆ m_queue


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