Skip to content

Commit

Permalink
coroutine: remove remnants of variadic futures
Browse files Browse the repository at this point in the history
Coroutine support still contains some remnants of variadic futures;
remove them to simplify the code.

The `awaiter` struct had three specializations, one for void, one
for one template parameter, and one for {zero, two+} parameters.
The first two remain.

without_preemption_check() also had three specializations, only one
remains.

Closes scylladb#2066
  • Loading branch information
avikivity authored and xemul committed Feb 1, 2024
1 parent 6d89909 commit 7729ab0
Showing 1 changed file with 11 additions and 42 deletions.
53 changes: 11 additions & 42 deletions include/seastar/core/coroutine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,33 +133,8 @@ public:
};
};

template<bool CheckPreempt, typename... T>
struct awaiter {
seastar::future<T...> _future;
public:
explicit awaiter(seastar::future<T...>&& f) noexcept : _future(std::move(f)) { }

awaiter(const awaiter&) = delete;
awaiter(awaiter&&) = delete;

bool await_ready() const noexcept {
return _future.available() && (!CheckPreempt || !need_preempt());
}

template<typename U>
void await_suspend(std::coroutine_handle<U> hndl) noexcept {
if (!CheckPreempt || !_future.available()) {
_future.set_coroutine(hndl.promise());
} else {
schedule(&hndl.promise());
}
}

std::tuple<T...> await_resume() { return _future.get(); }
};

template<bool CheckPreempt, typename T>
struct awaiter<CheckPreempt, T> {
struct awaiter {
seastar::future<T> _future;
public:
explicit awaiter(seastar::future<T>&& f) noexcept : _future(std::move(f)) { }
Expand All @@ -184,7 +159,7 @@ public:
};

template<bool CheckPreempt>
struct awaiter<CheckPreempt> {
struct awaiter<CheckPreempt, void> {
seastar::future<> _future;
public:
explicit awaiter(seastar::future<>&& f) noexcept : _future(std::move(f)) { }
Expand Down Expand Up @@ -212,9 +187,9 @@ public:

SEASTAR_MODULE_EXPORT_BEGIN

template<typename... T>
auto operator co_await(future<T...> f) noexcept {
return internal::awaiter<true, T...>(std::move(f));
template<typename T>
auto operator co_await(future<T> f) noexcept {
return internal::awaiter<true, T>(std::move(f));
}

namespace coroutine {
Expand All @@ -223,15 +198,9 @@ namespace coroutine {
/// If constructed from a future, co_await-ing it will bypass
/// checking if the task quota is depleted, which means that
/// a ready future will be handled immediately.
template<typename... T> struct [[nodiscard]] without_preemption_check : public seastar::future<T...> {
explicit without_preemption_check(seastar::future<T...>&& f) noexcept : seastar::future<T...>(std::move(f)) {}
};
template<typename T> struct [[nodiscard]] without_preemption_check<T> : public seastar::future<T> {
template<typename T> struct [[nodiscard]] without_preemption_check : public seastar::future<T> {
explicit without_preemption_check(seastar::future<T>&& f) noexcept : seastar::future<T>(std::move(f)) {}
};
template<> struct [[nodiscard]] without_preemption_check<> : public seastar::future<> {
explicit without_preemption_check(seastar::future<>&& f) noexcept : seastar::future<>(std::move(f)) {}
};

/// Make a lambda coroutine safe for use in an outer coroutine with
/// functions that accept continuations.
Expand Down Expand Up @@ -272,9 +241,9 @@ public:
/// Wait for a future without a preemption check
///
/// \param f a \c future<> wrapped with \c without_preemption_check
template<typename... T>
auto operator co_await(coroutine::without_preemption_check<T...> f) noexcept {
return internal::awaiter<false, T...>(std::move(f));
template<typename T>
auto operator co_await(coroutine::without_preemption_check<T> f) noexcept {
return internal::awaiter<false, T>(std::move(f));
}

SEASTAR_MODULE_EXPORT_END
Expand All @@ -285,8 +254,8 @@ SEASTAR_MODULE_EXPORT_END
namespace std {

SEASTAR_MODULE_EXPORT
template<typename... T, typename... Args>
class coroutine_traits<seastar::future<T...>, Args...> : public seastar::internal::coroutine_traits_base<T...> {
template<typename T, typename... Args>
class coroutine_traits<seastar::future<T>, Args...> : public seastar::internal::coroutine_traits_base<T> {
};

} // std
Expand Down

0 comments on commit 7729ab0

Please sign in to comment.