From f1c5606b2e4ad8b493d223ace6f0374540c80877 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 5 Oct 2024 21:06:18 +0800 Subject: [PATCH] treewide: replace boost::irange with std::views::iota where possible this change is created in the same spirit of f322e76. in this change, we partially modernizes our range usage while maintaining existing functionality. Signed-off-by: Kefu Chai --- apps/io_tester/io_tester.cc | 13 +++++++------ apps/iotune/iotune.cc | 4 ++-- apps/rpc_tester/rpc_tester.cc | 6 +++--- demos/rpc_demo.cc | 5 ++--- demos/scheduling_group_demo.cc | 6 +++--- demos/tls_simple_client_demo.cc | 5 ++--- doc/tutorial.md | 4 ++-- scripts/seastar-json2code.py | 6 +++--- src/core/prometheus.cc | 4 ++-- src/core/reactor.cc | 4 ++-- src/core/resource.cc | 4 ++-- src/core/sharded.cc | 4 ++-- tests/perf/fair_queue_perf.cc | 4 ++-- tests/perf/smp_submit_to_perf.cc | 6 +++--- tests/unit/alien_test.cc | 6 +++--- tests/unit/chunked_fifo_test.cc | 5 ++--- tests/unit/closeable_test.cc | 4 ++-- tests/unit/distributed_test.cc | 7 +++---- tests/unit/futures_test.cc | 9 +++++---- tests/unit/locking_test.cc | 16 ++++++++-------- tests/unit/loopback_socket.hh | 4 ++-- tests/unit/metrics_test.cc | 3 ++- tests/unit/semaphore_test.cc | 8 ++++---- tests/unit/stall_detector_test.cc | 6 +++--- tests/unit/tls_test.cc | 9 +++++---- 25 files changed, 76 insertions(+), 76 deletions(-) diff --git a/apps/io_tester/io_tester.cc b/apps/io_tester/io_tester.cc index 47a50fe0a54..10cc5c2cdc5 100644 --- a/apps/io_tester/io_tester.cc +++ b/apps/io_tester/io_tester.cc @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -108,7 +109,7 @@ future> create_and_fill_file(sstring name, uint64_t fs const uint64_t last_buffer_id = (buffers_count - 1u); const uint64_t last_write_position = buffer_size * last_buffer_id; - return do_with(boost::irange(UINT64_C(0), buffers_count), [f, buffer_size] (auto& buffers_range) mutable { + return do_with(std::views::iota(UINT64_C(0), buffers_count), [f, buffer_size] (auto& buffers_range) mutable { return max_concurrent_for_each(buffers_range.begin(), buffers_range.end(), 64, [f, buffer_size] (auto buffer_id) mutable { auto source_buffer = allocate_and_fill_buffer(buffer_size); auto write_position = buffer_id * buffer_size; @@ -338,7 +339,7 @@ class class_data { } future<> issue_requests_in_parallel(std::chrono::steady_clock::time_point stop) { - return parallel_for_each(boost::irange(0u, parallelism()), [this, stop] (auto dummy) mutable { + return parallel_for_each(std::views::iota(0u, parallelism()), [this, stop] (auto dummy) mutable { auto bufptr = allocate_aligned_buffer(this->req_size(), _alignment); auto buf = bufptr.get(); return do_until([this, stop] { return std::chrono::steady_clock::now() > stop || requests() > limit(); }, [this, buf, stop] () mutable { @@ -352,7 +353,7 @@ class class_data { future<> issue_requests_at_rate(std::chrono::steady_clock::time_point stop) { return do_with(io_intent{}, 0u, [this, stop] (io_intent& intent, unsigned& in_flight) { - return parallel_for_each(boost::irange(0u, parallelism()), [this, stop, &intent, &in_flight] (auto dummy) mutable { + return parallel_for_each(std::views::iota(0u, parallelism()), [this, stop, &intent, &in_flight] (auto dummy) mutable { auto bufptr = allocate_aligned_buffer(this->req_size(), _alignment); auto buf = bufptr.get(); auto pause = std::chrono::duration_cast(1s) / rps(); @@ -361,7 +362,7 @@ class class_data { return do_until([this, stop] { return std::chrono::steady_clock::now() > stop || requests() > limit(); }, [this, buf, stop, pause, &intent, &in_flight] () mutable { auto start = std::chrono::steady_clock::now(); in_flight++; - return parallel_for_each(boost::irange(0u, batch()), [this, buf, &intent, start, stop] (auto dummy) { + return parallel_for_each(std::views::iota(0u, batch()), [this, buf, &intent, start, stop] (auto dummy) { return issue_request(buf, &intent, start, stop); }).then([this, start, pause] { auto now = std::chrono::steady_clock::now(); @@ -752,7 +753,7 @@ class unlink_class_data : public class_data { return make_ready_future<>(); } - return max_concurrent_for_each(boost::irange(_file_id_to_remove, files_count()), max_concurrency(), [this] (uint64_t file_id) { + return max_concurrent_for_each(std::views::iota(_file_id_to_remove, files_count()), max_concurrency(), [this] (uint64_t file_id) { const auto fname = get_filename(file_id); return remove_file(fname); }); @@ -779,7 +780,7 @@ class unlink_class_data : public class_data { future<> do_start_on_directory(sstring path) { _dir_path = std::move(path); - return max_concurrent_for_each(boost::irange(UINT64_C(0), files_count()), max_concurrency(), [this] (uint64_t file_id) { + return max_concurrent_for_each(std::views::iota(UINT64_C(0), files_count()), max_concurrency(), [this] (uint64_t file_id) { const auto fname = get_filename(file_id); const auto fsize = align_up(_config.file_size / files_count(), extent_size_hint_alignment); const auto flags = open_flags::rw | open_flags::create; diff --git a/apps/iotune/iotune.cc b/apps/iotune/iotune.cc index 57c9a643a70..60a5554be1c 100644 --- a/apps/iotune/iotune.cc +++ b/apps/iotune/iotune.cc @@ -25,11 +25,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -468,7 +468,7 @@ class test_file { } auto worker = worker_ptr.get(); - auto concurrency = boost::irange(0, max_os_concurrency, 1); + auto concurrency = std::views::iota(0u, max_os_concurrency); return parallel_for_each(std::move(concurrency), [worker] (unsigned idx) { auto bufptr = worker->get_buffer(); auto buf = bufptr.get(); diff --git a/apps/rpc_tester/rpc_tester.cc b/apps/rpc_tester/rpc_tester.cc index e9dc2053b8d..805c5025ad4 100644 --- a/apps/rpc_tester/rpc_tester.cc +++ b/apps/rpc_tester/rpc_tester.cc @@ -22,9 +22,9 @@ #include #include #include +#include #include #include -#include #pragma GCC diagnostic push // see https://github.com/boostorg/accumulators/pull/54 #pragma GCC diagnostic ignored "-Wuninitialized" @@ -429,7 +429,7 @@ class job_rpc : public job { co.tcp_nodelay = _ccfg.nodelay; co.isolation_cookie = _cfg.sg_name; _client = std::make_unique(_rpc, co, _caddr); - return parallel_for_each(boost::irange(0u, _cfg.parallelism), [this] (auto dummy) { + return parallel_for_each(std::views::iota(0u, _cfg.parallelism), [this] (auto dummy) { auto f = make_ready_future<>(); if (_cfg.sleep_time) { // Do initial small delay to de-synchronize fibers @@ -513,7 +513,7 @@ class job_cpu : public job { virtual future<> run() override { _stop = std::chrono::steady_clock::now() + _cfg.duration; return with_scheduling_group(_cfg.sg, [this] { - return parallel_for_each(boost::irange(0u, _cfg.parallelism), [this] (auto dummy) { + return parallel_for_each(std::views::iota(0u, _cfg.parallelism), [this] (auto dummy) { return do_until([this] { return std::chrono::steady_clock::now() > _stop; }, [this] { diff --git a/demos/rpc_demo.cc b/demos/rpc_demo.cc index 9d4de202102..dd7abbfc8a7 100644 --- a/demos/rpc_demo.cc +++ b/demos/rpc_demo.cc @@ -19,6 +19,7 @@ * Copyright 2015 Cloudius Systems */ #include +#include #include #include #include @@ -27,8 +28,6 @@ #include #include -#include - using namespace seastar; struct serializer { @@ -229,7 +228,7 @@ int main(int ac, char** av) { (void)sleep(400ms).then([test12] () mutable { // server is configured for 10MB max, throw 25MB worth of requests at it. auto now = rpc::rpc_clock_type::now(); - return parallel_for_each(boost::irange(0, 25), [test12, now] (int idx) mutable { + return parallel_for_each(std::views::iota(0, 25), [test12, now] (int idx) mutable { return test12(*client, 100, uninitialized_string(1'000'000)).then([idx, now] { auto later = rpc::rpc_clock_type::now(); auto delta = std::chrono::duration_cast(later - now); diff --git a/demos/scheduling_group_demo.cc b/demos/scheduling_group_demo.cc index 7e801ad15d6..87fe28017e6 100644 --- a/demos/scheduling_group_demo.cc +++ b/demos/scheduling_group_demo.cc @@ -32,7 +32,7 @@ #include #include #include -#include +#include using namespace seastar; using namespace std::chrono_literals; @@ -78,7 +78,7 @@ future<> run_compute_intensive_tasks(seastar::scheduling_group sg, done_func done, unsigned concurrency, unsigned& counter, std::function (unsigned& counter)> task) { return seastar::async([task = std::move(task), sg, concurrency, done, &counter] () mutable { while (!done()) { - parallel_for_each(boost::irange(0u, concurrency), [task, sg, &counter] (unsigned i) mutable { + parallel_for_each(std::views::iota(0u, concurrency), [task, sg, &counter] (unsigned i) mutable { return with_scheduling_group(sg, [task, &counter] { return task(counter); }); @@ -92,7 +92,7 @@ future<> run_compute_intensive_tasks_in_threads(seastar::scheduling_group sg, done_func done, unsigned concurrency, unsigned& counter, std::function (unsigned& counter)> task) { auto attr = seastar::thread_attributes(); attr.sched_group = sg; - return parallel_for_each(boost::irange(0u, concurrency), [attr, done, &counter, task] (unsigned i) { + return parallel_for_each(std::views::iota(0u, concurrency), [attr, done, &counter, task] (unsigned i) { return seastar::async(attr, [done, &counter, task] { while (!done()) { task(counter).get(); diff --git a/demos/tls_simple_client_demo.cc b/demos/tls_simple_client_demo.cc index 014332c960c..0f93ec6e606 100644 --- a/demos/tls_simple_client_demo.cc +++ b/demos/tls_simple_client_demo.cc @@ -19,6 +19,7 @@ * Copyright 2015 Cloudius Systems */ #include +#include #include #include @@ -28,8 +29,6 @@ #include #include "tls_echo_server.hh" -#include - using namespace seastar; namespace bpo = boost::program_options; @@ -97,7 +96,7 @@ int main(int ac, char** av) { } return tls::connect(certs, ia, options).then([=](::connected_socket s) { auto strms = ::make_lw_shared(std::move(s)); - auto range = boost::irange(size_t(0), i); + auto range = std::views::iota(size_t(0), i); return do_for_each(range, [=](auto) { auto f = strms->out.write(*msg); if (!do_read) { diff --git a/doc/tutorial.md b/doc/tutorial.md index 96f63866492..a837093b549 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1619,7 +1619,7 @@ In the examples we saw earlier, `main()` ran our function `f()` only once, on th seastar::future<> service_loop(); seastar::future<> f() { - return seastar::parallel_for_each(boost::irange(0, seastar::smp::count), + return seastar::parallel_for_each(std::views::iota(0u, seastar::smp::count), [] (unsigned c) { return seastar::smp::submit_to(c, service_loop); }); @@ -2320,7 +2320,7 @@ Consider the following asynchronous function `loop()`, which loops until some sh ```cpp seastar::future loop(int parallelism, bool& stop) { return seastar::do_with(0L, [parallelism, &stop] (long& counter) { - return seastar::parallel_for_each(boost::irange(0, parallelism), + return seastar::parallel_for_each(std::views::iota(0u, parallelism), [&stop, &counter] (unsigned c) { return seastar::do_until([&stop] { return stop; }, [&counter] { ++counter; diff --git a/scripts/seastar-json2code.py b/scripts/seastar-json2code.py index 298bc9746fd..4b152ebfc30 100755 --- a/scripts/seastar-json2code.py +++ b/scripts/seastar-json2code.py @@ -487,8 +487,8 @@ def indent_body(s, level): static $wrapper end() { return $wrapper($enum_name::NUM_ITEMS); } - static boost::integer_range<$wrapper> all_items() { - return boost::irange(begin(), end()); + static std::ranges::iota_view<$wrapper, $wrapper> all_items() { + return std::views::iota(begin(), end()); } $enum_name v;""").substitute(enum_name=enum_name, wrapper=wrapper, @@ -537,7 +537,7 @@ def create_h_file(data, hfile_name, api_name, init_method, base_api): '', '']) - add_include(hfile, ['', '']) + add_include(hfile, ['', '']) open_namespace(hfile, "seastar") open_namespace(hfile, "httpd") open_namespace(hfile, api_name) diff --git a/src/core/prometheus.cc b/src/core/prometheus.cc index c22d6d3ed81..23c6ff557dc 100644 --- a/src/core/prometheus.cc +++ b/src/core/prometheus.cc @@ -33,9 +33,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -400,7 +400,7 @@ class metrics_families_per_shard { static future<> get_map_value(metrics_families_per_shard& vec) { vec.resize(smp::count); - return parallel_for_each(boost::irange(0u, smp::count), [&vec] (auto cpu) { + return parallel_for_each(std::views::iota(0u, smp::count), [&vec] (auto cpu) { return smp::submit_to(cpu, [] { return mi::get_values(); }).then([&vec, cpu] (auto res) { diff --git a/src/core/reactor.cc b/src/core/reactor.cc index de9afddc962..1b3b7205aff 100644 --- a/src/core/reactor.cc +++ b/src/core/reactor.cc @@ -31,6 +31,7 @@ module; #include #include #include +#include #include #include @@ -62,7 +63,6 @@ module; #include #include #include -#include #include #include #include @@ -1078,7 +1078,7 @@ reactor::~reactor() { // The following line will preserve the convention that constructor and destructor functions // for the per sg values are called in the context of the containing scheduling group. *internal::current_scheduling_group_ptr() = scheduling_group(tq->_id); - for (size_t key : boost::irange(0, sg_data.scheduling_group_key_configs.size())) { + for (size_t key : std::views::iota(0u, sg_data.scheduling_group_key_configs.size())) { void* val = this_sg.specific_vals[key]; if (val) { if (sg_data.scheduling_group_key_configs[key].destructor) { diff --git a/src/core/resource.cc b/src/core/resource.cc index 7dc64163a49..3464adc38f4 100644 --- a/src/core/resource.cc +++ b/src/core/resource.cc @@ -28,7 +28,7 @@ module; #include #include #include -#include +#include #include #include #include @@ -401,7 +401,7 @@ allocate_io_queues(hwloc_topology_t topology, std::vector cpus, std::unorde // above, hwloc won't do us any good here. Later on, we will use this information to assign // shards to coordinators that are node-local to themselves. std::unordered_map> numa_nodes; - for (auto shard: boost::irange(0, int(cpus.size()))) { + for (auto shard: std::views::iota(0, int(cpus.size()))) { auto node_id = node_of_shard(shard); if (numa_nodes.count(node_id) == 0) { diff --git a/src/core/sharded.cc b/src/core/sharded.cc index 8659ae6610c..c4c4b4feac8 100644 --- a/src/core/sharded.cc +++ b/src/core/sharded.cc @@ -23,7 +23,7 @@ module; #endif -#include +#include #ifdef SEASTAR_MODULE module seastar; @@ -39,7 +39,7 @@ namespace internal { future<> sharded_parallel_for_each(unsigned nr_shards, on_each_shard_func on_each_shard) noexcept(std::is_nothrow_move_constructible_v) { - return parallel_for_each(boost::irange(0, nr_shards), std::move(on_each_shard)); + return parallel_for_each(std::views::iota(0u, nr_shards), std::move(on_each_shard)); } } diff --git a/tests/perf/fair_queue_perf.cc b/tests/perf/fair_queue_perf.cc index 515f015f6ff..525b756fd40 100644 --- a/tests/perf/fair_queue_perf.cc +++ b/tests/perf/fair_queue_perf.cc @@ -27,7 +27,7 @@ #include #include #include -#include +#include static constexpr fair_queue::class_id cid = 0; @@ -98,7 +98,7 @@ struct perf_fair_queue { future<> perf_fair_queue::test(bool loc) { auto invokers = local_fq.invoke_on_all([loc] (local_fq_and_class& local) { - return parallel_for_each(boost::irange(0u, requests_to_dispatch), [&local, loc] (unsigned dummy) { + return parallel_for_each(std::views::iota(0u, requests_to_dispatch), [&local, loc] (unsigned dummy) { auto cap = local.queue(loc).tokens_capacity(double(1) / std::numeric_limits::max() + double(1) / std::numeric_limits::max()); auto req = std::make_unique(cap, [&local, loc, cap] { local.executed++; diff --git a/tests/perf/smp_submit_to_perf.cc b/tests/perf/smp_submit_to_perf.cc index f1a39e6fc2e..0e5f60d274b 100644 --- a/tests/perf/smp_submit_to_perf.cc +++ b/tests/perf/smp_submit_to_perf.cc @@ -20,7 +20,7 @@ */ #include -#include +#include #include #include #include @@ -55,7 +55,7 @@ class thinker { future<> _done; future<> start_thinking(unsigned concurrency) { - return parallel_for_each(boost::irange(0u, concurrency), [this] (unsigned f) { + return parallel_for_each(std::views::iota(0u, concurrency), [this] (unsigned f) { return do_until([this] { return _stop; }, [this] { auto until = steady_clock::now() + _pause.get(); while (steady_clock::now() < until) { @@ -116,7 +116,7 @@ class worker { } future<> start_working(unsigned concurrency, respond_type resp, microseconds tmo) { - return parallel_for_each(boost::irange(0u, concurrency), [this, resp, tmo] (unsigned f) { + return parallel_for_each(std::views::iota(0u, concurrency), [this, resp, tmo] (unsigned f) { return do_until([this] { return _stop; }, [this, resp, tmo] { return smp::submit_to(_to, [resp, tmo] { switch (resp) { diff --git a/tests/unit/alien_test.cc b/tests/unit/alien_test.cc index c827db37f6c..a5bf1753d9f 100644 --- a/tests/unit/alien_test.cc +++ b/tests/unit/alien_test.cc @@ -30,9 +30,9 @@ #include #include #include +#include #include -#include using namespace seastar; @@ -70,7 +70,7 @@ int main(int argc, char** argv) }); // test for alien::submit_to(), which returns a std::future std::vector> counts; - for (auto i : boost::irange(0u, smp::count)) { + for (auto i : std::views::iota(0u, smp::count)) { // send messages from alien. counts.push_back(alien::submit_to(app.alien(), i, [i] { return seastar::make_ready_future(i); @@ -122,7 +122,7 @@ int main(int argc, char** argv) std::cerr << "Bad everything: " << everything << " != " << expected << std::endl; return 1; } - const auto shards = boost::irange(0u, smp::count); + const auto shards = std::views::iota(0u, smp::count); auto expected = std::accumulate(std::begin(shards), std::end(shards), 0); if (total != expected) { std::cerr << "Bad total: " << total << " != " << expected << std::endl; diff --git a/tests/unit/chunked_fifo_test.cc b/tests/unit/chunked_fifo_test.cc index a8b78722a6d..99d5bf70bb8 100644 --- a/tests/unit/chunked_fifo_test.cc +++ b/tests/unit/chunked_fifo_test.cc @@ -22,7 +22,6 @@ #define BOOST_TEST_MODULE core -#include #include #include @@ -142,8 +141,8 @@ BOOST_AUTO_TEST_CASE(chunked_fifo_pop_n) { } }; - for (size_t size : boost::irange((size_t)0, 2 * N) ) { - for (size_t pop_count : boost::irange((size_t)0, size + 1) ) { + for (size_t size : std::views::iota((size_t)0, 2 * N) ) { + for (size_t pop_count : std::views::iota((size_t)0, size + 1) ) { BOOST_TEST_CONTEXT("size: " << size << ", pop_count: " << pop_count) { fill_and_reset(size); diff --git a/tests/unit/closeable_test.cc b/tests/unit/closeable_test.cc index 561c2511c7d..63b801ad99c 100644 --- a/tests/unit/closeable_test.cc +++ b/tests/unit/closeable_test.cc @@ -21,7 +21,7 @@ #include -#include +#include #include #include @@ -363,7 +363,7 @@ SEASTAR_TEST_CASE(gate_holder_parallel_copy_test) { auto gh = g.hold(); // Copying the gate::holder in the lambda below should keep it open // until all instances complete - (void)parallel_for_each(boost::irange(0, expected), [&count, gh = gh] (int) { + (void)parallel_for_each(std::views::iota(0, expected), [&count, gh = gh] (int) { count++; return make_ready_future<>(); }); diff --git a/tests/unit/distributed_test.cc b/tests/unit/distributed_test.cc index a044e3546b8..ead09f6815d 100644 --- a/tests/unit/distributed_test.cc +++ b/tests/unit/distributed_test.cc @@ -32,8 +32,7 @@ #include #include #include - -#include +#include using namespace seastar; using namespace std::chrono_literals; @@ -347,8 +346,8 @@ SEASTAR_TEST_CASE(test_smp_service_groups) { shard_id other_shard = smp::count - 1; remote_worker rm1(1); remote_worker rm2(1000); - auto bunch1 = parallel_for_each(boost::irange(0, 20), [&] (int ignore) { return rm1.do_remote_work(other_shard, ssg1); }); - auto bunch2 = parallel_for_each(boost::irange(0, 2000), [&] (int ignore) { return rm2.do_remote_work(other_shard, ssg2); }); + auto bunch1 = parallel_for_each(std::views::iota(0, 20), [&] (int ignore) { return rm1.do_remote_work(other_shard, ssg1); }); + auto bunch2 = parallel_for_each(std::views::iota(0, 2000), [&] (int ignore) { return rm2.do_remote_work(other_shard, ssg2); }); bunch1.get(); bunch2.get(); if (smp::count > 1) { diff --git a/tests/unit/futures_test.cc b/tests/unit/futures_test.cc index 2daf7d51823..0af2d825c87 100644 --- a/tests/unit/futures_test.cc +++ b/tests/unit/futures_test.cc @@ -19,12 +19,13 @@ * Copyright (C) 2014 Cloudius Systems, Ltd. */ -#include "seastar/core/loop.hh" #include #include #include #include #include +#include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -53,7 +55,6 @@ #include #include -#include #include using namespace seastar; @@ -1011,7 +1012,7 @@ SEASTAR_TEST_CASE(test_parallel_for_each) { SEASTAR_TEST_CASE(test_parallel_for_each_early_failure) { return do_with(0, [] (int& counter) { - return parallel_for_each(boost::irange(0, 11000), [&counter] (int i) { + return parallel_for_each(std::views::iota(0, 11000), [&counter] (int i) { using namespace std::chrono_literals; // force scheduling return sleep((i % 31 + 1) * 1ms).then([&counter, i] { @@ -1038,7 +1039,7 @@ SEASTAR_TEST_CASE(test_parallel_for_each_early_failure) { SEASTAR_TEST_CASE(test_parallel_for_each_waits_for_all_fibers_even_if_one_of_them_failed) { auto can_exit = make_lw_shared(false); - return parallel_for_each(boost::irange(0, 2), [can_exit] (int i) { + return parallel_for_each(std::views::iota(0, 2), [can_exit] (int i) { return yield().then([i, can_exit] { if (i == 1) { throw expected_exception(); diff --git a/tests/unit/locking_test.cc b/tests/unit/locking_test.cc index ec157b2eadd..36bd19b6ee5 100644 --- a/tests/unit/locking_test.cc +++ b/tests/unit/locking_test.cc @@ -21,8 +21,10 @@ */ #include - #include +#include +#include + #include #include #include @@ -33,8 +35,6 @@ #include #include #include -#include -#include using namespace seastar; using namespace std::chrono_literals; @@ -67,7 +67,7 @@ SEASTAR_TEST_CASE(test_with_lock_mutable) { SEASTAR_TEST_CASE(test_rwlock_exclusive) { return do_with(rwlock(), unsigned(0), [] (rwlock& l, unsigned& counter) { - return parallel_for_each(boost::irange(0, 10), [&l, &counter] (int idx) { + return parallel_for_each(std::views::iota(0, 10), [&l, &counter] (int idx) { return with_lock(l.for_write(), [&counter] { BOOST_REQUIRE_EQUAL(counter, 0u); ++counter; @@ -82,7 +82,7 @@ SEASTAR_TEST_CASE(test_rwlock_exclusive) { SEASTAR_TEST_CASE(test_rwlock_shared) { return do_with(rwlock(), unsigned(0), unsigned(0), [] (rwlock& l, unsigned& counter, unsigned& max) { - return parallel_for_each(boost::irange(0, 10), [&l, &counter, &max] (int idx) { + return parallel_for_each(std::views::iota(0, 10), [&l, &counter, &max] (int idx) { return with_lock(l.for_read(), [&counter, &max] { ++counter; max = std::max(max, counter); @@ -216,7 +216,7 @@ SEASTAR_THREAD_TEST_CASE(test_shared_mutex) { SEASTAR_TEST_CASE(test_shared_mutex_exclusive) { return do_with(shared_mutex(), unsigned(0), [] (shared_mutex& sm, unsigned& counter) { - return parallel_for_each(boost::irange(0, 10), [&sm, &counter] (int idx) { + return parallel_for_each(std::views::iota(0, 10), [&sm, &counter] (int idx) { return with_lock(sm, [&counter] { BOOST_REQUIRE_EQUAL(counter, 0u); ++counter; @@ -231,7 +231,7 @@ SEASTAR_TEST_CASE(test_shared_mutex_exclusive) { SEASTAR_TEST_CASE(test_shared_mutex_shared) { return do_with(shared_mutex(), unsigned(0), unsigned(0), [] (shared_mutex& sm, unsigned& counter, unsigned& max) { - return parallel_for_each(boost::irange(0, 10), [&sm, &counter, &max] (int idx) { + return parallel_for_each(std::views::iota(0, 10), [&sm, &counter, &max] (int idx) { return with_shared(sm, [&counter, &max] { ++counter; max = std::max(max, counter); @@ -454,7 +454,7 @@ SEASTAR_TEST_CASE(test_shared_mutex_exclusive_locks) { shared_mutex sm{}; unsigned counter = 0; - co_await coroutine::parallel_for_each(boost::irange(0, 10), coroutine::lambda([&sm, &counter] (auto&&) -> future<> { + co_await coroutine::parallel_for_each(std::views::iota(0, 10), coroutine::lambda([&sm, &counter] (auto&&) -> future<> { const auto ulock = co_await get_unique_lock(sm); BOOST_REQUIRE_EQUAL(counter, 0u); ++counter; diff --git a/tests/unit/loopback_socket.hh b/tests/unit/loopback_socket.hh index 5ff1b264f38..bc5406fcb3f 100644 --- a/tests/unit/loopback_socket.hh +++ b/tests/unit/loopback_socket.hh @@ -21,6 +21,7 @@ #pragma once +#include #include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include namespace seastar { @@ -284,7 +284,7 @@ public: _pending[shard] = nullptr; } future<> destroy_all_shards() { - return parallel_for_each(boost::irange(0u, _shards_count), [this](shard_id shard) { + return parallel_for_each(std::views::iota(0u, _shards_count), [this](shard_id shard) { return smp::submit_to(shard, [this] { destroy_shard(this_shard_id()); }); diff --git a/tests/unit/metrics_test.cc b/tests/unit/metrics_test.cc index 8142747ef92..4fca814f776 100644 --- a/tests/unit/metrics_test.cc +++ b/tests/unit/metrics_test.cc @@ -36,6 +36,7 @@ #include #include #include +#include SEASTAR_TEST_CASE(test_add_group) { using namespace seastar::metrics; @@ -84,7 +85,7 @@ SEASTAR_THREAD_TEST_CASE(test_renaming_scheuling_groups) { static const char* name1 = "A"; static const char* name2 = "B"; scheduling_group sg = create_scheduling_group("hello", 111).get(); - boost::integer_range rng(0, 1000); + auto rng = std::views::iota(0, 1000); // repeatedly change the group name back and forth in // decresing time intervals to see if it generate double //registration statistics errors. diff --git a/tests/unit/semaphore_test.cc b/tests/unit/semaphore_test.cc index 7038451aa6a..89addad72bb 100644 --- a/tests/unit/semaphore_test.cc +++ b/tests/unit/semaphore_test.cc @@ -31,7 +31,7 @@ #include #include #include -#include +#include using namespace seastar; using namespace std::chrono_literals; @@ -175,7 +175,7 @@ SEASTAR_THREAD_TEST_CASE(test_non_default_broken_semaphore) { SEASTAR_TEST_CASE(test_shared_mutex_exclusive) { return do_with(shared_mutex(), unsigned(0), [] (shared_mutex& sm, unsigned& counter) { - return parallel_for_each(boost::irange(0, 10), [&sm, &counter] (int idx) { + return parallel_for_each(std::views::iota(0, 10), [&sm, &counter] (int idx) { return with_lock(sm, [&counter] { BOOST_REQUIRE_EQUAL(counter, 0u); ++counter; @@ -200,7 +200,7 @@ SEASTAR_TEST_CASE(test_shared_mutex_shared) { }); }); }; - return map_reduce(boost::irange(0, 100), running_in_parallel, false, std::bit_or()).then([&counter] (bool result) { + return map_reduce(std::views::iota(0, 100), running_in_parallel, false, std::bit_or()).then([&counter] (bool result) { BOOST_REQUIRE_EQUAL(result, true); BOOST_REQUIRE_EQUAL(counter, 0u); }); @@ -237,7 +237,7 @@ SEASTAR_TEST_CASE(test_shared_mutex_mixed) { return running_in_parallel(instance); } }; - return map_reduce(boost::irange(0, 100), run, false, std::bit_or()).then([&counter] (bool result) { + return map_reduce(std::views::iota(0, 100), run, false, std::bit_or()).then([&counter] (bool result) { BOOST_REQUIRE_EQUAL(result, true); BOOST_REQUIRE_EQUAL(counter, 0u); }); diff --git a/tests/unit/stall_detector_test.cc b/tests/unit/stall_detector_test.cc index 4213889048a..7392cf465e1 100644 --- a/tests/unit/stall_detector_test.cc +++ b/tests/unit/stall_detector_test.cc @@ -30,9 +30,9 @@ #include #include #include -#include +#include -#include +#include #ifndef SEASTAR_DEBUG @@ -118,7 +118,7 @@ SEASTAR_THREAD_TEST_CASE(no_poll_no_stall) { static constexpr unsigned tasks = 2000; promise<> p; auto f = p.get_future(); - parallel_for_each(boost::irange(0u, tasks), [&p] (unsigned int i) { + parallel_for_each(std::views::iota(0u, tasks), [&p] (unsigned int i) { (void)yield().then([i, &p] { spin(500us); if (i == tasks - 1) { diff --git a/tests/unit/tls_test.cc b/tests/unit/tls_test.cc index ee200b603dc..2c41b16d463 100644 --- a/tests/unit/tls_test.cc +++ b/tests/unit/tls_test.cc @@ -20,6 +20,7 @@ * Copyright (C) 2015 Cloudius Systems, Ltd. */ +#include #include #include @@ -156,7 +157,7 @@ SEASTAR_TEST_CASE(test_x509_client_with_builder_system_trust_multiple) { (void)b.set_system_trust(); auto creds = b.build_certificate_credentials(); - return parallel_for_each(boost::irange(0, 20), [creds](auto i) { return connect_to_ssl_google(creds); }); + return parallel_for_each(std::views::iota(0, 20), [creds](auto i) { return connect_to_ssl_google(creds); }); }); } @@ -292,7 +293,7 @@ SEASTAR_THREAD_TEST_CASE(test_x509_client_with_builder_multiple) { b.set_x509_trust_file(server.cert(), tls::x509_crt_format::PEM).get(); auto creds = b.build_certificate_credentials(); auto addr = server.addr(); - parallel_for_each(boost::irange(0, 20), [creds, addr](auto i) { + parallel_for_each(std::views::iota(0, 20), [creds, addr](auto i) { return connect_to_ssl_addr(creds, addr); }).get(); } @@ -593,7 +594,7 @@ static future<> run_echo_test(sstring message, }).then([=] { return tls::connect(certs, addr, tls::tls_options{.server_name=name}).then([loops, msg, do_read](::connected_socket s) { auto strms = ::make_lw_shared(std::move(s)); - auto range = boost::irange(0, loops); + auto range = std::views::iota(0, loops); return do_for_each(range, [strms, msg](auto) { auto f = strms->out.write(*msg); return f.then([strms, msg]() { @@ -764,7 +765,7 @@ SEASTAR_TEST_CASE(test_many_large_message_x509_client_server) { // Sending a huge-ish message a and immediately closing the session (see params) // provokes case where tls::vec_push entered race and asserted on broken IO state // machine. - auto range = boost::irange(0, 20); + auto range = std::views::iota(0, 20); return do_for_each(range, [msg = std::move(msg)](auto) { return run_echo_test(std::move(msg), 1, certfile("catest.pem"), "test.scylladb.org", certfile("test.crt"), certfile("test.key"), tls::client_auth::NONE, {}, {}, false); });