Skip to content

Commit 79c4ef1

Browse files
committed
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.
1 parent b5ca08a commit 79c4ef1

File tree

8 files changed

+15
-148
lines changed

8 files changed

+15
-148
lines changed

.drone.star

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def main(ctx):
1919
linux_cxx("GCC Valgrind", "g++", packages="g++-14 libssl-dev valgrind", image="cppalliance/droneubuntu2404:1", buildtype="boost_v1", buildscript="drone", environment={ "VARIANT": "beast_valgrind", "TOOLSET": "gcc", "COMPILER": "g++", "CXXSTD": "11" }, globalenv=globalenv),
2020
linux_cxx("Default g++", "g++", packages="mlocate", image="cppalliance/droneubuntu1604:1", buildtype="boost_v1", buildscript="drone", environment={ "VARIANT": "release", "TOOLSET": "gcc", "COMPILER": "g++", "CXXSTD": "11" }, globalenv=globalenv),
2121
linux_cxx("GCC 8, C++17, libstdc++, release", "g++-8", packages="g++-8 mlocate", image="cppalliance/droneubuntu1604:1", buildtype="boost_v1", buildscript="drone", environment={ "VARIANT": "release", "TOOLSET": "gcc", "COMPILER": "g++-8", "CXXSTD" : "17" }, globalenv=globalenv),
22+
linux_cxx("GCC 14, -DBOOST_ASIO_NO_TS_EXECUTORS", "g++-14", packages="g++-14", image="cppalliance/droneubuntu2404:1", buildtype="boost_v1", buildscript="drone", environment={ "VARIANT": "release", "TOOLSET": "gcc", "COMPILER": "g++-14", "CXXSTD" : "20" , "CXX_FLAGS": "<cxxflags>-DBOOST_ASIO_NO_TS_EXECUTORS"}, globalenv=globalenv),
2223
linux_cxx("Clang 18, UBasan", "clang++-18", packages="clang-18 libssl-dev", image="cppalliance/droneubuntu2404:1", buildtype="boost_v1", buildscript="drone", environment={"VARIANT": "beast_ubasan", "TOOLSET": "clang", "COMPILER": "clang++-18", "CXXSTD": "17", "UBSAN_OPTIONS": 'print_stacktrace=1', "DRONE_BEFORE_INSTALL": "UBasan" }, globalenv=globalenv, privileged=True),
2324
linux_cxx("docs", "", packages="docbook docbook-xml docbook-xsl xsltproc libsaxonhe-java default-jre-headless flex libfl-dev bison unzip rsync mlocate", image="cppalliance/droneubuntu1804:1", buildtype="docs", buildscript="drone", environment={"COMMENT": "docs"}, globalenv=globalenv),
2425
linux_cxx("GCC 14, UBasan", "g++-14", packages="g++-14", buildtype="boost", buildscript="drone", image="cppalliance/droneubuntu2404:1", environment={'COMMENT': 'ubsan', 'B2_VARIANT': 'debug', 'B2_TOOLSET': 'gcc-14', 'B2_CXXSTD': '14,17,20,23', 'B2_UBSAN': '1', 'B2_DEFINES': 'BOOST_NO_STRESS_TEST=1', 'B2_LINKFLAGS': '-fuse-ld=gold'}, globalenv=globalenv, privileged=True),

example/advanced/server-flex-awaitable/advanced_server_flex_awaitable.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,9 @@ handle_signals(task_group& task_group)
581581
}
582582
else // SIGTERM
583583
{
584-
executor.get_inner_executor().context().stop();
584+
net::query(
585+
executor.get_inner_executor(),
586+
net::execution::context).stop();
585587
}
586588
}
587589

include/boost/beast/_experimental/test/impl/stream.hpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,8 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
5757
Handler h_;
5858
boost::weak_ptr<detail::stream_state> wp_;
5959
Buffers b_;
60-
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
61-
net::any_io_executor wg2_;
62-
#else // defined(BOOST_ASIO_NO_TS_EXECUTORS)
6360
net::executor_work_guard<
6461
net::associated_executor_t<Handler, net::any_io_executor>> wg2_;
65-
#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS)
66-
6762
lambda(lambda&&) = default;
6863
lambda(lambda const&) = default;
6964

@@ -75,15 +70,7 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
7570
: h_(std::forward<Handler_>(h))
7671
, wp_(s)
7772
, b_(b)
78-
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
79-
, wg2_(net::prefer(
80-
net::get_associated_executor(
81-
h_, s->exec),
82-
net::execution::outstanding_work.tracked))
83-
#else // defined(BOOST_ASIO_NO_TS_EXECUTORS)
84-
, wg2_(net::get_associated_executor(
85-
h_, s->exec))
86-
#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS)
73+
, wg2_(net::get_associated_executor(h_, s->exec))
8774
{
8875
}
8976

@@ -131,15 +118,9 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
131118
}
132119
}
133120

134-
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
135-
net::dispatch(wg2_,
136-
net::append(std::move(h_), ec, bytes_transferred));
137-
wg2_ = net::any_io_executor(); // probably unnecessary
138-
#else // defined(BOOST_ASIO_NO_TS_EXECUTORS)
139121
net::dispatch(wg2_.get_executor(),
140122
net::append(std::move(h_), ec, bytes_transferred));
141123
wg2_.reset();
142-
#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS)
143124
}
144125
};
145126

include/boost/beast/core/async_base.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
#include <boost/beast/core/detail/allocator.hpp>
1515
#include <boost/beast/core/detail/async_base.hpp>
1616
#include <boost/beast/core/detail/filtering_cancellation_slot.hpp>
17-
#include <boost/beast/core/detail/work_guard.hpp>
1817
#include <boost/asio/append.hpp>
1918
#include <boost/asio/associated_allocator.hpp>
2019
#include <boost/asio/associated_cancellation_slot.hpp>
2120
#include <boost/asio/associated_executor.hpp>
2221
#include <boost/asio/associated_immediate_executor.hpp>
2322
#include <boost/asio/bind_executor.hpp>
2423
#include <boost/asio/dispatch.hpp>
24+
#include <boost/asio/executor_work_guard.hpp>
2525
#include <boost/asio/handler_continuation_hook.hpp>
2626
#include <boost/asio/post.hpp>
2727
#include <boost/core/exchange.hpp>
@@ -186,7 +186,7 @@ class async_base
186186
"Executor type requirements not met");
187187

188188
Handler h_;
189-
detail::select_work_guard_t<Executor1> wg1_;
189+
net::executor_work_guard<Executor1> wg1_;
190190
net::cancellation_type act_{net::cancellation_type::terminal};
191191
public:
192192
/** The type of executor associated with this object.
@@ -202,7 +202,7 @@ class async_base
202202
typename
203203
net::associated_executor<
204204
Handler,
205-
typename detail::select_work_guard_t<Executor1>::executor_type
205+
typename net::executor_work_guard<Executor1>::executor_type
206206
>::type;
207207
#endif
208208

@@ -260,7 +260,7 @@ class async_base
260260
Handler_&& handler,
261261
Executor1 const& ex1)
262262
: h_(std::forward<Handler_>(handler))
263-
, wg1_(detail::make_work_guard(ex1))
263+
, wg1_(ex1)
264264
{
265265
}
266266

@@ -327,10 +327,10 @@ class async_base
327327
handler, then the object returned from this function will be used
328328
as the associated immediate executor of the derived class.
329329
*/
330-
auto
330+
net::associated_immediate_executor_t<
331+
Handler,
332+
typename net::executor_work_guard<Executor1>::executor_type>
331333
get_immediate_executor() const noexcept
332-
-> decltype(net::get_associated_immediate_executor(
333-
h_, wg1_.get_executor()))
334334
{
335335
return net::get_associated_immediate_executor(
336336
h_, wg1_.get_executor());

include/boost/beast/core/detail/work_guard.hpp

Lines changed: 0 additions & 102 deletions
This file was deleted.

include/boost/beast/core/impl/saved_handler.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,15 @@ class saved_handler::impl final : public base
6666
};
6767

6868
ebo_pair v_;
69-
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
70-
typename std::decay<decltype(net::prefer(std::declval<
71-
net::associated_executor_t<Handler>>(),
72-
net::execution::outstanding_work.tracked))>::type
73-
wg2_;
74-
#else // defined(BOOST_ASIO_NO_TS_EXECUTORS)
7569
net::executor_work_guard<
7670
net::associated_executor_t<Handler>> wg2_;
77-
#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS)
7871
net::cancellation_slot slot_{net::get_associated_cancellation_slot(v_.h)};
7972
public:
8073
template<class Handler_>
8174
impl(alloc_type const& a, Handler_&& h,
8275
saved_handler * owner)
8376
: base(owner), v_(a, std::forward<Handler_>(h))
84-
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
85-
, wg2_(net::prefer(
86-
net::get_associated_executor(v_.h),
87-
net::execution::outstanding_work.tracked))
88-
#else // defined(BOOST_ASIO_NO_TS_EXECUTORS)
8977
, wg2_(net::get_associated_executor(v_.h))
90-
#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS)
9178
{
9279
}
9380

test/beast/core/test_handler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class simple_executor
6969
template<class F>
7070
void execute(F&&) const {}
7171
simple_executor prefer(net::execution::outstanding_work_t::tracked_t) const { return *this; }
72+
simple_executor require(net::execution::blocking_t::never_t) const { return *this; };
7273
#else
7374
void* context() { return nullptr; }
7475
void on_work_started() {}

test/extras/include/boost/beast/test/yield_to.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ class BOOST_BEAST_SYMBOL_HIDDEN enable_yield_to
4141
net::io_context ioc_;
4242

4343
private:
44-
beast::detail::select_work_guard_t<
45-
net::io_context::executor_type>
46-
work_;
44+
net::executor_work_guard<net::io_context::executor_type> work_;
4745
std::vector<std::thread> threads_;
4846
std::mutex m_;
4947
std::condition_variable cv_;
@@ -56,8 +54,7 @@ class BOOST_BEAST_SYMBOL_HIDDEN enable_yield_to
5654

5755
explicit
5856
enable_yield_to(std::size_t concurrency = 1)
59-
: work_(beast::detail::make_work_guard(
60-
ioc_.get_executor()))
57+
: work_(ioc_.get_executor())
6158
{
6259
threads_.reserve(concurrency);
6360
while(concurrency--)

0 commit comments

Comments
 (0)