Skip to content

Commit a8b82db

Browse files
authored
Merge pull request ceph#65062 from adamemerson/wip-redirect-error
common/async: improved `redirect_error`, `run_coro`, and tests Reviewed-by: Anthony D'Atri [email protected] Reviewed-by: Casey Bodley [email protected] Reviewed-by: Jesse F. Williamson [email protected]
2 parents 7da2ef3 + c050cc8 commit a8b82db

File tree

9 files changed

+959
-66
lines changed

9 files changed

+959
-66
lines changed

COPYING

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ Copyright: 2020 Red Hat <[email protected]>
211211
2003-2019 Christopher M. Kohlhoff <[email protected]>
212212
License: Boost Software License, Version 1.0
213213

214+
Files: src/common/async/redirect_error.h,
215+
src/test/common/test_async_redirect_error.cc
216+
Copyright: 2025 Contributors to the Ceph Project
217+
2003-2024 Christopher M. Kohlhoff <[email protected]>
218+
License: Boost Software License, Version 1.0
219+
214220
Files: src/script/backport-create-issue
215221
Copyright: 2015 Red Hat <[email protected]>
216222
2018 SUSE LLC

src/common/async/blocked_completion.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,44 @@
1616
#ifndef CEPH_COMMON_ASYNC_BLOCKED_COMPLETION_H
1717
#define CEPH_COMMON_ASYNC_BLOCKED_COMPLETION_H
1818

19+
/// \file common/async/blocked_completion.h
20+
///
21+
/// \brief A blocking `completion token`
22+
///
23+
/// This completion token will actually hard-block your thread. Do not
24+
/// do so within an `io_context` thread.
25+
1926
#include <condition_variable>
2027
#include <mutex>
2128
#include <optional>
2229

2330
#include <boost/asio/async_result.hpp>
24-
#include <boost/asio/redirect_error.hpp>
31+
#include <boost/asio/disposition.hpp>
2532

2633
#include <boost/system/error_code.hpp>
2734

28-
#include <common/async/concepts.h>
35+
#include "common/async/redirect_error.h"
2936

3037
namespace ceph::async {
31-
32-
namespace bs = boost::system;
33-
38+
/// A \ref `completion token` type that blocks the current thread
39+
/// until the operation completes.
40+
///
41+
/// \warning Keep deadlocks in mind. Do not use in threads that expect
42+
/// to be asynchronous.
3443
class use_blocked_t {
3544
public:
3645
use_blocked_t() = default;
3746

38-
auto operator [](bs::error_code& ec) const {
39-
return boost::asio::redirect_error(use_blocked_t{}, ec);
47+
/// Redirect the \ref `disposition` of the operation to a
48+
/// variable. (A `disposition` is a concept generalizing error codes
49+
/// and exceptions.)
50+
template<boost::asio::disposition Disposition>
51+
auto operator [](Disposition& d) const {
52+
return redirect_error(use_blocked_t{}, d);
4053
}
4154
};
4255

56+
/// The archetypical instance of `use_blocked_t`
4357
inline constexpr use_blocked_t use_blocked;
4458

4559
namespace detail {

0 commit comments

Comments
 (0)