diff --git a/libs/async/include/psemek/async/event_loop.hpp b/libs/async/include/psemek/async/event_loop.hpp index 35b7d9db..f19ca05e 100644 --- a/libs/async/include/psemek/async/event_loop.hpp +++ b/libs/async/include/psemek/async/event_loop.hpp @@ -17,6 +17,8 @@ namespace psemek::async void stop() override; + void clear() override; + void wait() override; void wait_for(clock::duration period) override; diff --git a/libs/async/include/psemek/async/executor.hpp b/libs/async/include/psemek/async/executor.hpp index 56e3c004..ae7a1348 100644 --- a/libs/async/include/psemek/async/executor.hpp +++ b/libs/async/include/psemek/async/executor.hpp @@ -29,6 +29,9 @@ namespace psemek::async // NB: the executor must call stop() from destructor. virtual void stop() = 0; + // Clear the pending tasks queue. + virtual void clear() = 0; + // Wait for all the tasks to be executed. // May take forever. virtual void wait() = 0; diff --git a/libs/async/include/psemek/async/synchronous_executor.hpp b/libs/async/include/psemek/async/synchronous_executor.hpp index 45b6fa3f..cc273176 100644 --- a/libs/async/include/psemek/async/synchronous_executor.hpp +++ b/libs/async/include/psemek/async/synchronous_executor.hpp @@ -14,6 +14,8 @@ namespace psemek::async void stop() override; + void clear() override; + void wait() override; void wait_for(clock::duration period) override; diff --git a/libs/async/include/psemek/async/threadpool.hpp b/libs/async/include/psemek/async/threadpool.hpp index 99b1501b..852349e2 100644 --- a/libs/async/include/psemek/async/threadpool.hpp +++ b/libs/async/include/psemek/async/threadpool.hpp @@ -31,6 +31,8 @@ namespace psemek::async void stop() override; + void clear() override; + void wait() override; void wait_for(clock::duration period) override; diff --git a/libs/async/source/event_loop.cpp b/libs/async/source/event_loop.cpp index 546694c8..0fdac888 100644 --- a/libs/async/source/event_loop.cpp +++ b/libs/async/source/event_loop.cpp @@ -1,7 +1,5 @@ #include -#include - namespace psemek::async { @@ -20,6 +18,11 @@ namespace psemek::async queue_.clear(); } + void event_loop::clear() + { + queue_.clear(); + } + void event_loop::wait() { while (!queue_.empty()) diff --git a/libs/async/source/synchronous_executor.cpp b/libs/async/source/synchronous_executor.cpp index 57179ce3..1662b854 100644 --- a/libs/async/source/synchronous_executor.cpp +++ b/libs/async/source/synchronous_executor.cpp @@ -1,8 +1,6 @@ #include #include -#include - namespace psemek::async { @@ -19,6 +17,9 @@ namespace psemek::async void synchronous_executor::stop() {} + void synchronous_executor::clear() + {} + void synchronous_executor::wait() {} diff --git a/libs/async/source/threadpool.cpp b/libs/async/source/threadpool.cpp index 81f8d8eb..f163b935 100644 --- a/libs/async/source/threadpool.cpp +++ b/libs/async/source/threadpool.cpp @@ -85,6 +85,11 @@ namespace psemek::async threads_.clear(); } + void threadpool::clear() + { + task_queue_.clear(); + } + void threadpool::wait() { std::unique_lock lock{working_count_mutex_};