Skip to content

Commit 19c38c3

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 7847855 commit 19c38c3

File tree

11 files changed

+25
-173
lines changed

11 files changed

+25
-173
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),

cmake/toolchains/gcc.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
include(${CMAKE_CURRENT_LIST_DIR}/common.cmake)
33

44
# Compiler options.
5-
add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter)
5+
add_compile_options(-Wall -Wextra -Wpedantic)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ net::awaitable<void, executor_type>
362362
run_websocket_session(
363363
Stream& stream,
364364
beast::flat_buffer& buffer,
365-
http::request<http::string_body> req,
366-
beast::string_view doc_root)
365+
http::request<http::string_body> req)
367366
{
368367
auto cs = co_await net::this_coro::cancellation_state;
369368
auto ws = websocket::stream<Stream&>{ stream };
@@ -438,7 +437,7 @@ run_session(
438437
beast::get_lowest_layer(stream).expires_never();
439438

440439
co_await run_websocket_session(
441-
stream, buffer, parser.release(), doc_root);
440+
stream, buffer, parser.release());
442441

443442
co_return;
444443
}
@@ -581,7 +580,9 @@ handle_signals(task_group& task_group)
581580
}
582581
else // SIGTERM
583582
{
584-
executor.get_inner_executor().context().stop();
583+
net::query(
584+
executor.get_inner_executor(),
585+
net::execution::context).stop();
585586
}
586587
}
587588

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <boost/asio/append.hpp>
1818
#include <boost/asio/associated_cancellation_slot.hpp>
1919
#include <boost/asio/dispatch.hpp>
20+
#include <boost/asio/executor_work_guard.hpp>
2021
#include <boost/asio/post.hpp>
2122
#include <mutex>
2223
#include <stdexcept>
@@ -57,13 +58,8 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
5758
Handler h_;
5859
boost::weak_ptr<detail::stream_state> wp_;
5960
Buffers b_;
60-
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
61-
net::any_io_executor wg2_;
62-
#else // defined(BOOST_ASIO_NO_TS_EXECUTORS)
6361
net::executor_work_guard<
6462
net::associated_executor_t<Handler, net::any_io_executor>> wg2_;
65-
#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS)
66-
6763
lambda(lambda&&) = default;
6864
lambda(lambda const&) = default;
6965

@@ -75,15 +71,7 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
7571
: h_(std::forward<Handler_>(h))
7672
, wp_(s)
7773
, 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)
74+
, wg2_(net::get_associated_executor(h_, s->exec))
8775
{
8876
}
8977

@@ -131,24 +119,14 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
131119
}
132120
}
133121

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)
139122
net::dispatch(wg2_.get_executor(),
140123
net::append(std::move(h_), ec, bytes_transferred));
141124
wg2_.reset();
142-
#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS)
143125
}
144126
};
145127

146128
lambda fn_;
147-
#if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
148129
net::executor_work_guard<net::any_io_executor> wg1_;
149-
#else
150-
net::any_io_executor wg1_;
151-
#endif
152130

153131
public:
154132
template<class Handler_>
@@ -157,25 +135,15 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
157135
boost::shared_ptr<detail::stream_state> const& s,
158136
Buffers const& b)
159137
: fn_(std::forward<Handler_>(h), s, b)
160-
#if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
161138
, wg1_(s->exec)
162-
#else
163-
, wg1_(net::prefer(s->exec,
164-
net::execution::outstanding_work.tracked))
165-
#endif
166139
{
167140
}
168141

169142
void
170143
operator()(error_code ec) override
171144
{
172-
#if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
173145
net::post(wg1_.get_executor(), net::append(std::move(fn_), ec));
174146
wg1_.reset();
175-
#else
176-
net::post(wg1_, net::append(std::move(fn_), ec));
177-
wg1_ = net::any_io_executor(); // probably unnecessary
178-
#endif
179147
}
180148
};
181149

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <boost/asio/async_result.hpp>
2020
#include <boost/asio/buffer.hpp>
2121
#include <boost/asio/error.hpp>
22-
#include <boost/asio/executor_work_guard.hpp>
2322
#include <boost/asio/any_io_executor.hpp>
2423
#include <boost/asio/io_context.hpp>
2524
#include <boost/assert.hpp>

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/async_base.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,31 @@ struct ex1_type
4444
{
4545

4646
net::execution_context &
47-
query(net::execution::context_t c) const noexcept
47+
query(net::execution::context_t) const noexcept
4848
{ return *reinterpret_cast<net::execution_context *>(&ex1ctx); }
4949

5050
net::execution::blocking_t
5151
query(net::execution::blocking_t) const noexcept
5252
{ return net::execution::blocking; };
5353

5454
net::execution::outstanding_work_t
55-
query(net::execution::outstanding_work_t w) const noexcept
55+
query(net::execution::outstanding_work_t) const noexcept
5656
{ return net::execution::outstanding_work; }
5757

5858
ex1_type
59-
require(net::execution::blocking_t::possibly_t b) const
59+
require(net::execution::blocking_t::possibly_t) const
6060
{ return *this; }
6161

6262
ex1_type
63-
require(net::execution::blocking_t::never_t b) const
63+
require(net::execution::blocking_t::never_t) const
6464
{ return *this; };
6565

6666
ex1_type
67-
prefer(net::execution::outstanding_work_t::untracked_t w) const
67+
prefer(net::execution::outstanding_work_t::untracked_t) const
6868
{ return *this; };
6969

7070
ex1_type
71-
prefer(net::execution::outstanding_work_t::tracked_t w) const
71+
prefer(net::execution::outstanding_work_t::tracked_t) const
7272
{ return *this; };
7373

7474
template<class F>

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() {}

0 commit comments

Comments
 (0)