15 #ifndef SCARAB_CONCURRENT_QUEUE_HH_ 16 #define SCARAB_CONCURRENT_QUEUE_HH_ 21 #include <condition_variable> 27 LOGGER( slog_cq,
"concurrent_queue" );
29 template<
class XDataType >
33 typedef std::deque< XDataType >
queue;
43 return ! f_queue.empty();
47 typedef std::unique_lock< std::mutex >
cq_lock;
74 void push( XDataType
const& a_data )
76 LDEBUG( slog_cq,
"Attempting to push to queue" );
77 cq_lock lock( f_mutex );
78 LDEBUG( slog_cq,
"Pushing to concurrent queue; size: " << f_queue.size() );
79 f_queue.push_back( a_data );
81 f_condition_var.notify_one();
87 cq_lock lock( f_mutex );
88 return f_queue.empty();
93 cq_lock lock( f_mutex );
94 return f_queue.size();
99 cq_lock lock( f_mutex );
101 if( f_queue.empty() )
106 a_popped_value = f_queue.front();
113 cq_lock lock( f_mutex );
122 a_popped_value = f_queue.front();
124 LDEBUG( slog_cq,
"Popping from concurrent queue; size: " << f_queue.size() );
130 cq_lock lock( f_mutex );
132 std::chrono::steady_clock::time_point
const waitUntil = std::chrono::steady_clock::now() +
f_timeout;
133 if( ! f_condition_var.wait_until( lock, waitUntil,
queue_not_empty( f_queue ) ) )
144 a_popped_value = f_queue.front();
146 LDEBUG( slog_cq,
"Popping from concurrent queue; size: " << f_queue.size() );
153 f_condition_var.notify_one();
159 return f_timeout.count();
164 f_timeout = std::chrono::milliseconds( a_duration );
unsigned get_timeout() const
queue_not_empty(queue &a_queue)
LOGGER(mtlog, "authentication")
Contains the logger class and macros, based on Kasper's KLogger class.
void set_timeout(unsigned a_duration)
bool timed_wait_and_pop(XDataType &a_popped_value)
bool wait_and_pop(XDataType &a_popped_value)
virtual ~concurrent_queue()
bool try_pop(XDataType &a_popped_value)
std::condition_variable f_condition_var
std::deque< XDataType > queue
void push(XDataType const &a_data)
std::chrono::milliseconds f_timeout
std::mutex f_mutex
Timeout duration in milliseconds.
std::unique_lock< std::mutex > cq_lock