Skip to content

Commit 1cefcae

Browse files
committed
common/async: remove null_yield support for max_concurrent_for_each()
max_concurrent_for_each() is a thin wrapper around spawn_throttle. remove its support for null_yield too Signed-off-by: Casey Bodley <[email protected]>
1 parent cd0b62f commit 1cefcae

File tree

2 files changed

+7
-86
lines changed

2 files changed

+7
-86
lines changed

src/common/async/max_concurrent_for_each.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <boost/asio/spawn.hpp>
2323
#include "cancel_on_error.h"
2424
#include "co_throttle.h"
25-
#include "yield_context.h"
2625
#include "spawn_throttle.h"
2726

2827
namespace ceph::async {
@@ -37,10 +36,10 @@ namespace ceph::async {
3736
/// \code
3837
/// void child(task& t, boost::asio::yield_context yield);
3938
///
40-
/// void parent(std::span<task> tasks, optional_yield y)
39+
/// void parent(std::span<task> tasks, boost::asio::yield_context yield)
4140
/// {
4241
/// // process all tasks, up to 10 at a time
43-
/// max_concurrent_for_each(tasks, 10, y, child);
42+
/// max_concurrent_for_each(tasks, 10, yield, child);
4443
/// }
4544
/// \endcode
4645
template <typename Iterator, typename Sentinel, typename Func,
@@ -51,14 +50,14 @@ template <typename Iterator, typename Sentinel, typename Func,
5150
void max_concurrent_for_each(Iterator begin,
5251
Sentinel end,
5352
size_t max_concurrent,
54-
optional_yield y,
53+
boost::asio::yield_context yield,
5554
Func&& func,
5655
cancel_on_error on_error = cancel_on_error::none)
5756
{
5857
if (begin == end) {
5958
return;
6059
}
61-
auto throttle = spawn_throttle{y, max_concurrent, on_error};
60+
auto throttle = spawn_throttle{yield, max_concurrent, on_error};
6261
for (Iterator i = begin; i != end; ++i) {
6362
throttle.spawn([&func, &val = *i] (boost::asio::yield_context yield) {
6463
func(val, yield);
@@ -74,13 +73,13 @@ template <typename Range, typename Func,
7473
std::invocable<Func, Reference, boost::asio::yield_context>)
7574
auto max_concurrent_for_each(Range&& range,
7675
size_t max_concurrent,
77-
optional_yield y,
76+
boost::asio::yield_context yield,
7877
Func&& func,
7978
cancel_on_error on_error = cancel_on_error::none)
8079
{
8180
return max_concurrent_for_each(std::begin(range), std::end(range),
82-
max_concurrent, y, std::forward<Func>(func),
83-
on_error);
81+
max_concurrent, yield,
82+
std::forward<Func>(func), on_error);
8483
}
8584

8685
// \overload

src/test/common/test_async_max_concurrent_for_each.cc

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -49,84 +49,6 @@ struct null_sentinel {};
4949
bool operator==(const char* c, null_sentinel) { return !*c; }
5050
static_assert(std::sentinel_for<null_sentinel, const char*>);
5151

52-
TEST(iterator_null_yield, empty)
53-
{
54-
int* end = nullptr;
55-
auto cr = [] (int, asio::yield_context) {};
56-
max_concurrent_for_each(end, end, 10, null_yield, cr);
57-
}
58-
59-
TEST(iterator_null_yield, over_limit)
60-
{
61-
int concurrent = 0;
62-
int max_concurrent = 0;
63-
int completed = 0;
64-
65-
auto cr = [&] (int, asio::yield_context yield) {
66-
++concurrent;
67-
if (max_concurrent < concurrent) {
68-
max_concurrent = concurrent;
69-
}
70-
71-
wait_for(1ms, yield);
72-
73-
--concurrent;
74-
++completed;
75-
};
76-
77-
constexpr auto arr = std::array{1,2,3,4,5,6,7,8,9,10};
78-
max_concurrent_for_each(begin(arr), end(arr), 2, null_yield, cr);
79-
80-
EXPECT_EQ(0, concurrent);
81-
EXPECT_EQ(2, max_concurrent);
82-
EXPECT_EQ(10, completed);
83-
}
84-
85-
TEST(iterator_null_yield, sentinel)
86-
{
87-
const char* begin = "hello";
88-
null_sentinel end;
89-
90-
size_t completed = 0;
91-
auto cr = [&completed] (char c, asio::yield_context) { ++completed; };
92-
max_concurrent_for_each(begin, end, 10, null_yield, cr);
93-
EXPECT_EQ(completed, 5);
94-
}
95-
96-
TEST(range_null_yield, empty)
97-
{
98-
constexpr std::array<int, 0> arr{};
99-
auto cr = [] (int, asio::yield_context) {};
100-
max_concurrent_for_each(arr, 10, null_yield, cr);
101-
}
102-
103-
TEST(range_null_yield, over_limit)
104-
{
105-
int concurrent = 0;
106-
int max_concurrent = 0;
107-
int completed = 0;
108-
109-
auto cr = [&] (int, asio::yield_context yield) {
110-
++concurrent;
111-
if (max_concurrent < concurrent) {
112-
max_concurrent = concurrent;
113-
}
114-
115-
wait_for(1ms, yield);
116-
117-
--concurrent;
118-
++completed;
119-
};
120-
121-
constexpr auto arr = std::array{1,2,3,4,5,6,7,8,9,10};
122-
max_concurrent_for_each(arr, 2, null_yield, cr);
123-
124-
EXPECT_EQ(0, concurrent);
125-
EXPECT_EQ(2, max_concurrent);
126-
EXPECT_EQ(10, completed);
127-
}
128-
129-
13052
TEST(iterator_yield, empty)
13153
{
13254
int* end = nullptr;

0 commit comments

Comments
 (0)