Replace detail/work_guard.hpp with net::executor_work_guard

In newer versions of Asio, `executor_work_guard<>` can be used even when
`ASIO_NO_TS_EXECUTORS` is defined.
This commit is contained in:
Mohammad Nejati
2025-04-27 10:04:53 +00:00
committed by Mohammad Nejati
parent 78478557f6
commit 19c38c308a
11 changed files with 25 additions and 173 deletions

View File

@@ -44,7 +44,7 @@ struct ex1_type
{
net::execution_context &
query(net::execution::context_t c) const noexcept
query(net::execution::context_t) const noexcept
{ return *reinterpret_cast<net::execution_context *>(&ex1ctx); }
net::execution::blocking_t
@@ -52,23 +52,23 @@ struct ex1_type
{ return net::execution::blocking; };
net::execution::outstanding_work_t
query(net::execution::outstanding_work_t w) const noexcept
query(net::execution::outstanding_work_t) const noexcept
{ return net::execution::outstanding_work; }
ex1_type
require(net::execution::blocking_t::possibly_t b) const
require(net::execution::blocking_t::possibly_t) const
{ return *this; }
ex1_type
require(net::execution::blocking_t::never_t b) const
require(net::execution::blocking_t::never_t) const
{ return *this; };
ex1_type
prefer(net::execution::outstanding_work_t::untracked_t w) const
prefer(net::execution::outstanding_work_t::untracked_t) const
{ return *this; };
ex1_type
prefer(net::execution::outstanding_work_t::tracked_t w) const
prefer(net::execution::outstanding_work_t::tracked_t) const
{ return *this; };
template<class F>

View File

@@ -69,6 +69,7 @@ public:
template<class F>
void execute(F&&) const {}
simple_executor prefer(net::execution::outstanding_work_t::tracked_t) const { return *this; }
simple_executor require(net::execution::blocking_t::never_t) const { return *this; };
#else
void* context() { return nullptr; }
void on_work_started() {}

View File

@@ -41,9 +41,7 @@ protected:
net::io_context ioc_;
private:
beast::detail::select_work_guard_t<
net::io_context::executor_type>
work_;
net::executor_work_guard<net::io_context::executor_type> work_;
std::vector<std::thread> threads_;
std::mutex m_;
std::condition_variable cv_;
@@ -56,8 +54,7 @@ public:
explicit
enable_yield_to(std::size_t concurrency = 1)
: work_(beast::detail::make_work_guard(
ioc_.get_executor()))
: work_(ioc_.get_executor())
{
threads_.reserve(concurrency);
while(concurrency--)