7 #include <condition_variable>
30 std::function<
void( T
const & ) > on_drop_callback =
nullptr )
49 _queue.push_back(std::move(item));
82 _queue.push_back(std::move(item));
94 bool dequeue( T * item,
unsigned int timeout_ms )
98 std::chrono::milliseconds( timeout_ms ),
99 [
this]() { return ! _accepting || ! _queue.empty(); } )
105 *item = std::move(
_queue.front());
122 *item = std::move(
_queue.front());
204 std::function<
void( T
const & ) > on_drop_callback =
nullptr )
205 :
_queue( cap, on_drop_callback )
211 if( item->is_blocking() )
212 return _queue.blocking_enqueue( std::move( item ) );
214 return _queue.enqueue( std::move( item ) );
217 bool dequeue(T* item,
unsigned int timeout_ms)
219 return _queue.dequeue(item, timeout_ms);
224 return _queue.try_dequeue(item);
295 template<
class Duration >
298 using namespace std::chrono;
300 std::unique_lock<std::mutex>
lock(
_owner->_was_stopped_mutex);
318 std::function<
void(
action ) > on_drop_callback =
nullptr );
332 void invoke(T item,
bool is_blocking =
false)
337 _queue.blocking_enqueue(std::move(item));
339 _queue.enqueue(std::move(item));
346 void invoke_and_wait(T item, std::function<
bool()> exit_condition,
bool is_blocking =
false)
351 auto func = std::move(item);
379 bool flush(std::chrono::steady_clock::duration
timeout = std::chrono::seconds(10) );
405 template<
class T = std::function<
void(dispatcher::cancellable_timer)>>
410 : _operation(
std::move(operation)), _dispatcher(1), _stopped(true)
424 if (!_stopped.load()) {
461 _timeout_ms(timeout_ms), _operation(
std::move(operation))
469 std::lock_guard<std::mutex> lk(_m);
481 void start() { std::lock_guard<std::mutex> lk(_m); _watcher->start(); _running =
true; }
482 void stop() { { std::lock_guard<std::mutex> lk(_m); _running =
false; } _watcher->stop(); }
483 bool running() { std::lock_guard<std::mutex> lk(_m);
return _running; }
485 void kick() { std::lock_guard<std::mutex> lk(_m); _kicked =
true; }
490 bool _kicked =
false;
491 bool _running =
false;