Skip to content

Commit

Permalink
treewide: do not check for SEASTAR_COROUTINES_ENABLED
Browse files Browse the repository at this point in the history
since we've dropped the support for C++17, and we even started using
C++20 coroutines in 1d56a1d unconditionally in the implementation
of Seastar, there is no need to check the support of coroutine anymore.

so, in this change, we

* stop check and define SEASTAR_COROUTINES_ENABLED
* do not check SEASTAR_COROUTINES_ENABLED
* drop the code for handling the case where SEASTAR_COROUTINES_ENABLED
  is not defined.

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed May 19, 2024
1 parent a7fb8ff commit 12f6cef
Show file tree
Hide file tree
Showing 16 changed files with 13 additions and 103 deletions.
11 changes: 0 additions & 11 deletions demos/coroutines_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@

#include <seastar/util/std-compat.hh>

#ifndef SEASTAR_COROUTINES_ENABLED

int main(int argc, char** argv) {
std::cout << "coroutines not available\n";
return 0;
}

#else

#include <seastar/core/app-template.hh>
#include <seastar/core/coroutine.hh>
#include <seastar/core/fstream.hh>
Expand Down Expand Up @@ -68,5 +59,3 @@ int main(int argc, char** argv) {
std::cout << "done\n";
});
}

#endif
9 changes: 1 addition & 8 deletions include/seastar/core/condition-variable.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
#include <functional>
#endif

#include <seastar/core/coroutine.hh>
#include <seastar/core/timer.hh>
#ifdef SEASTAR_COROUTINES_ENABLED
# include <seastar/core/coroutine.hh>
#endif
#include <seastar/core/loop.hh>
#include <seastar/util/modules.hh>

Expand Down Expand Up @@ -102,7 +100,6 @@ private:
}
};

#ifdef SEASTAR_COROUTINES_ENABLED
struct [[nodiscard("must co_await a when() call")]] awaiter : public waiter {
condition_variable* _cv;
promise<> _p;
Expand Down Expand Up @@ -183,7 +180,6 @@ private:
}
}
};
#endif

boost::intrusive::list<waiter, boost::intrusive::constant_time_size<false>> _waiters;
std::exception_ptr _ex; //"broken" exception
Expand Down Expand Up @@ -298,7 +294,6 @@ public:
return wait(timer<>::clock::now() + timeout, std::forward<Pred>(pred));
}

#ifdef SEASTAR_COROUTINES_ENABLED
/// Coroutine/co_await only waiter.
/// Waits until condition variable is signaled, may wake up without condition been met
///
Expand Down Expand Up @@ -381,8 +376,6 @@ public:
return when(timer<>::clock::now() + timeout, std::forward<Pred>(pred));
}

#endif

/// Whether or not the condition variable currently has pending waiter(s)
/// The returned answer is valid until next continuation/fiber switch.
bool has_waiters() const noexcept {
Expand Down
3 changes: 0 additions & 3 deletions include/seastar/core/coroutine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@


#ifndef SEASTAR_MODULE
#ifndef SEASTAR_COROUTINES_ENABLED
#error Coroutines support disabled.
#endif
#include <coroutine>
#endif

Expand Down
6 changes: 0 additions & 6 deletions include/seastar/core/file.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
#pragma once

#include <seastar/util/std-compat.hh>
#ifdef SEASTAR_COROUTINES_ENABLED
#include <seastar/core/coroutine.hh>
#include <seastar/coroutine/generator.hh>
#endif
#include <seastar/core/do_with.hh>
#include <seastar/core/stream.hh>
#include <seastar/core/sstring.hh>
Expand Down Expand Up @@ -170,11 +168,9 @@ public:
virtual future<> close() = 0;
virtual std::unique_ptr<file_handle_impl> dup();
virtual subscription<directory_entry> list_directory(std::function<future<> (directory_entry de)> next) = 0;
#ifdef SEASTAR_COROUTINES_ENABLED
// due to https://github.com/scylladb/seastar/issues/1913, we cannot use
// buffered generator yet.
virtual coroutine::experimental::generator<directory_entry> experimental_list_directory();
#endif
};

future<shared_ptr<file_impl>> make_file_impl(int fd, file_open_options options, int oflags, struct stat st) noexcept;
Expand Down Expand Up @@ -688,12 +684,10 @@ public:
/// Returns a directory listing, given that this file object is a directory.
subscription<directory_entry> list_directory(std::function<future<> (directory_entry de)> next);

#ifdef SEASTAR_COROUTINES_ENABLED
/// Returns a directory listing, given that this file object is a directory.
// due to https://github.com/scylladb/seastar/issues/1913, we cannot use
// buffered generator yet.
coroutine::experimental::generator<directory_entry> experimental_list_directory();
#endif

#if SEASTAR_API_LEVEL < 7
/**
Expand Down
5 changes: 1 addition & 4 deletions include/seastar/core/future.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1142,9 +1142,7 @@ protected:

void do_wait() noexcept;

#ifdef SEASTAR_COROUTINES_ENABLED
void set_coroutine(task& coroutine) noexcept;
#endif

friend class promise_base;
};
Expand Down Expand Up @@ -1769,9 +1767,8 @@ public:
_state.ignore();
}

#ifdef SEASTAR_COROUTINES_ENABLED
using future_base::set_coroutine;
#endif

private:
void set_task(task& t) noexcept {
assert(_promise);
Expand Down
8 changes: 1 addition & 7 deletions include/seastar/testing/perf_tests.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@

#include <fmt/format.h>

#include <seastar/core/coroutine.hh>
#include <seastar/core/future.hh>
#include <seastar/core/loop.hh>
#include <seastar/testing/linux_perf_event.hh>

#ifdef SEASTAR_COROUTINES_ENABLED
#include <seastar/core/coroutine.hh>
#endif

using namespace seastar;

namespace perf_tests {
Expand Down Expand Up @@ -362,7 +359,6 @@ void do_not_optimize(const T& v)
test_##test_group##_##test_case##_registrar(#test_group, #test_case); \
[[gnu::always_inline]] auto test_##test_group##_##test_case::run()

#ifdef SEASTAR_COROUTINES_ENABLED

#define PERF_TEST_C(test_group, test_case) \
struct test_##test_group##_##test_case : test_group { \
Expand All @@ -379,5 +375,3 @@ void do_not_optimize(const T& v)
static ::perf_tests::internal::test_registrar<test_##test_group##_##test_case> \
test_##test_group##_##test_case##_registrar(#test_group, #test_case); \
future<size_t> test_##test_group##_##test_case::run()

#endif // SEASTAR_COROUTINES_ENABLED
8 changes: 0 additions & 8 deletions include/seastar/util/std-compat.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ namespace std::pmr {
}
#endif

#if defined(__cpp_impl_coroutine) || defined(__cpp_coroutines)
#if __has_include(<coroutine>)
#define SEASTAR_COROUTINES_ENABLED
#else
#error Please use a C++ compiler with C++20 coroutines support
#endif
#endif

// Defining SEASTAR_ASAN_ENABLED in here is a bit of a hack, but
// convenient since it is build system independent and in practice
// everything includes this header.
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ target_compile_definitions (seastar-module
$<$<BOOL:${Seastar_SSTRING}>:SEASTAR_SSTRING>
SEASTAR_API_LEVEL=${Seastar_API_LEVEL}
SEASTAR_SCHEDULING_GROUPS_COUNT=${Seastar_SCHEDULING_GROUPS_COUNT}
SEASTAR_COROUTINES_ENABLED
PRIVATE
SEASTAR_MODULE)
target_compile_options (seastar-module
Expand Down
2 changes: 0 additions & 2 deletions src/core/file-impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ public:
virtual future<> close() noexcept override;
virtual std::unique_ptr<seastar::file_handle_impl> dup() override;
virtual subscription<directory_entry> list_directory(std::function<future<> (directory_entry de)> next) override;
#ifdef SEASTAR_COROUTINES_ENABLED
virtual coroutine::experimental::generator<directory_entry> experimental_list_directory() override;
#endif

#if SEASTAR_API_LEVEL >= 7
virtual future<size_t> read_dma(uint64_t pos, void* buffer, size_t len, io_intent* intent) noexcept override = 0;
Expand Down
8 changes: 0 additions & 8 deletions src/core/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ module;

#include <algorithm>
#include <atomic>
#ifdef SEASTAR_COROUTINES_ENABLED
#include <coroutine>
#endif
#include <deque>
#include <filesystem>
#include <functional>
Expand Down Expand Up @@ -399,7 +397,6 @@ static std::optional<directory_entry_type> dirent_type(const linux_dirent64& de)
return type;
}

#ifdef SEASTAR_COROUTINES_ENABLED
static coroutine::experimental::generator<directory_entry> make_list_directory_generator(int fd) {
temporary_buffer<char> buf(8192);

Expand Down Expand Up @@ -432,7 +429,6 @@ coroutine::experimental::generator<directory_entry> posix_file_impl::experimenta
// is allocated out of this buffer, so the buffer would grow up to ~200 bytes
return make_list_directory_generator(_fd);
}
#endif

subscription<directory_entry>
posix_file_impl::list_directory(std::function<future<> (directory_entry de)> next) {
Expand Down Expand Up @@ -1167,11 +1163,9 @@ file::list_directory(std::function<future<>(directory_entry de)> next) {
return _file_impl->list_directory(std::move(next));
}

#ifdef SEASTAR_COROUTINES_ENABLED
coroutine::experimental::generator<directory_entry> file::experimental_list_directory() {
return _file_impl->experimental_list_directory();
}
#endif

future<int> file::ioctl(uint64_t cmd, void* argp) noexcept {
return _file_impl->ioctl(cmd, argp);
Expand Down Expand Up @@ -1376,7 +1370,6 @@ file_impl::dup() {
throw std::runtime_error("this file type cannot be duplicated");
}

#ifdef SEASTAR_COROUTINES_ENABLED
static coroutine::experimental::generator<directory_entry> make_list_directory_fallback_generator(file_impl& me) {
queue<std::optional<directory_entry>> ents(16);
auto lister = me.list_directory([&ents] (directory_entry de) {
Expand All @@ -1400,7 +1393,6 @@ static coroutine::experimental::generator<directory_entry> make_list_directory_f
coroutine::experimental::generator<directory_entry> file_impl::experimental_list_directory() {
return make_list_directory_fallback_generator(*this);
}
#endif

future<int> file_impl::ioctl(uint64_t cmd, void* argp) noexcept {
return make_exception_future<int>(std::runtime_error("this file type does not support ioctl"));
Expand Down
2 changes: 0 additions & 2 deletions src/core/future.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,9 @@ void internal::future_base::do_wait() noexcept {
thread_impl::switch_out(thread);
}

#ifdef SEASTAR_COROUTINES_ENABLED
void internal::future_base::set_coroutine(task& coroutine) noexcept {
assert(_promise);
_promise->set_task(&coroutine);
}
#endif

}
4 changes: 0 additions & 4 deletions tests/perf/coroutine_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#include <seastar/testing/perf_tests.hh>

#ifdef SEASTAR_COROUTINES_ENABLED

#include <seastar/core/coroutine.hh>
#include <seastar/coroutine/maybe_yield.hh>

Expand All @@ -48,5 +46,3 @@ PERF_TEST_C(coroutine_test, maybe_yield)
{
co_await coroutine::maybe_yield();
}

#endif // SEASTAR_COROUTINES_ENABLED
11 changes: 2 additions & 9 deletions tests/perf/future_util_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
#include <boost/range/irange.hpp>

#include <seastar/testing/perf_tests.hh>
#include <seastar/core/loop.hh>
#include <seastar/util/later.hh>

#ifdef SEASTAR_COROUTINES_ENABLED
#include <seastar/core/coroutine.hh>
#include <seastar/coroutine/parallel_for_each.hh>
#endif
#include <seastar/core/loop.hh>
#include <seastar/util/later.hh>

struct parallel_for_each {
std::vector<int> empty_range;
Expand Down Expand Up @@ -157,8 +154,6 @@ PERF_TEST_F(parallel_for_each, suspend_100)
});
}

#ifdef SEASTAR_COROUTINES_ENABLED

PERF_TEST_C(parallel_for_each, cor_empty)
{
co_await seastar::parallel_for_each(empty_range, [] (int) -> future<> {
Expand Down Expand Up @@ -352,5 +347,3 @@ PERF_TEST_CN(parallel_for_each, cor_pfe_suspend_100)
perf_tests::do_not_optimize(value);
co_return range.size();
}

#endif // SEASTAR_COROUTINES_ENABLED
4 changes: 0 additions & 4 deletions tests/unit/condition_variable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ SEASTAR_THREAD_TEST_CASE(test_condition_variable_has_waiter) {
BOOST_REQUIRE_EQUAL(cv.has_waiters(), false);
}

#ifdef SEASTAR_COROUTINES_ENABLED

SEASTAR_TEST_CASE(test_condition_variable_signal_consume_coroutine) {
condition_variable cv;

Expand Down Expand Up @@ -365,5 +363,3 @@ SEASTAR_TEST_CASE(test_condition_variable_when_timeout) {

co_await std::move(f);
}

#endif
27 changes: 8 additions & 19 deletions tests/unit/coroutines_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,23 @@
#include <ranges>

#include <seastar/core/circular_buffer.hh>
#include <seastar/core/coroutine.hh>
#include <seastar/core/future-util.hh>
#include <seastar/testing/test_case.hh>
#include <seastar/core/sleep.hh>
#include <seastar/util/later.hh>
#include <seastar/core/thread.hh>
#include <seastar/testing/random.hh>

using namespace seastar;
using namespace std::chrono_literals;

#ifndef SEASTAR_COROUTINES_ENABLED

SEASTAR_TEST_CASE(test_coroutines_not_compiled_in) {
return make_ready_future<>();
}

#else

#include <seastar/core/coroutine.hh>
#include <seastar/coroutine/all.hh>
#include <seastar/coroutine/maybe_yield.hh>
#include <seastar/coroutine/switch_to.hh>
#include <seastar/coroutine/parallel_for_each.hh>
#include <seastar/coroutine/as_future.hh>
#include <seastar/coroutine/exception.hh>
#include <seastar/coroutine/generator.hh>
#include <seastar/testing/random.hh>
#include <seastar/testing/test_case.hh>
#include <seastar/util/later.hh>

using namespace seastar;
using namespace std::chrono_literals;

namespace {

Expand Down Expand Up @@ -520,7 +511,7 @@ SEASTAR_TEST_CASE(test_maybe_yield) {
BOOST_REQUIRE(true); // the test will hang if it doesn't work.
}

#if __has_include(<coroutine>) && !defined(__clang__)
#ifndef __clang__

#include "tl-generator.hh"
tl::generator<int> simple_generator(int max)
Expand Down Expand Up @@ -917,5 +908,3 @@ SEASTAR_TEST_CASE(test_lambda_coroutine_in_continuation) {
}));
BOOST_REQUIRE_EQUAL(sin1, sin2);
}

#endif
7 changes: 0 additions & 7 deletions tests/unit/directory_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ future<> lister_test() {
});
}

#ifdef SEASTAR_COROUTINES_ENABLED
future<> lister_generator_test(file f) {
auto lister = f.experimental_list_directory();
while (auto de = co_await lister()) {
Expand Down Expand Up @@ -134,12 +133,6 @@ future<> lister_generator_test() {
auto f2 = file(std::move(tf));
co_await lister_generator_test(std::move(f2));
}
#else
future<> lister_generator_test() {
fmt::print("Generator lister test skipped, coroutines not enabled\n");
return make_ready_future<>();
}
#endif

int main(int ac, char** av) {
return app_template().run(ac, av, [] {
Expand Down

0 comments on commit 12f6cef

Please sign in to comment.