Support async::executor::clear()
This commit is contained in:
parent
78e9731d8d
commit
615ee51229
7 changed files with 22 additions and 4 deletions
|
|
@ -17,6 +17,8 @@ namespace psemek::async
|
|||
|
||||
void stop() override;
|
||||
|
||||
void clear() override;
|
||||
|
||||
void wait() override;
|
||||
|
||||
void wait_for(clock::duration period) override;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ namespace psemek::async
|
|||
|
||||
void stop() override;
|
||||
|
||||
void clear() override;
|
||||
|
||||
void wait() override;
|
||||
|
||||
void wait_for(clock::duration period) override;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ namespace psemek::async
|
|||
|
||||
void stop() override;
|
||||
|
||||
void clear() override;
|
||||
|
||||
void wait() override;
|
||||
|
||||
void wait_for(clock::duration period) override;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#include <psemek/async/event_loop.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
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())
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
#include <psemek/async/synchronous_executor.hpp>
|
||||
#include <psemek/util/exception.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace psemek::async
|
||||
{
|
||||
|
||||
|
|
@ -19,6 +17,9 @@ namespace psemek::async
|
|||
void synchronous_executor::stop()
|
||||
{}
|
||||
|
||||
void synchronous_executor::clear()
|
||||
{}
|
||||
|
||||
void synchronous_executor::wait()
|
||||
{}
|
||||
|
||||
|
|
|
|||
|
|
@ -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_};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue