Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sharded.hh: migrate to concepts #2460

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions include/seastar/core/sharded.hh
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public:
/// \return Future that becomes ready once all calls have completed
template <typename Func, typename... Args>
requires std::invocable<Func, Service&, internal::sharded_unwrap_t<Args>...>
&& std::is_same_v<futurize_t<std::invoke_result_t<Func, Service&, internal::sharded_unwrap_t<Args>...>>, future<>>
future<> invoke_on_all(smp_submit_to_options options, Func func, Args... args) noexcept;

/// Invoke a function on all instances of `Service`.
Expand All @@ -301,6 +302,7 @@ public:
/// \ref smp::submit_to() called behind the scenes.
template <typename Func, typename... Args>
requires std::invocable<Func, Service&, internal::sharded_unwrap_t<Args>...>
&& std::is_same_v<futurize_t<std::invoke_result_t<Func, Service&, internal::sharded_unwrap_t<Args>...>>, future<>>
future<> invoke_on_all(Func func, Args... args) noexcept {
try {
return invoke_on_all(smp_submit_to_options{}, std::move(func), std::move(args)...);
Expand All @@ -321,6 +323,7 @@ public:
/// processed the message.
template <typename Func, typename... Args>
requires std::invocable<Func, Service&, Args...>
&& std::is_same_v<futurize_t<std::invoke_result_t<Func, Service&, Args...>>, future<>>
future<> invoke_on_others(smp_submit_to_options options, Func func, Args... args) noexcept;

/// Invoke a callable on all instances of \c Service except the instance
Expand All @@ -336,6 +339,7 @@ public:
/// \ref smp::submit_to() called behind the scenes.
template <typename Func, typename... Args>
requires std::invocable<Func, Service&, Args...>
&& std::is_same_v<futurize_t<std::invoke_result_t<Func, Service&, Args...>>, future<>>
future<> invoke_on_others(Func func, Args... args) noexcept {
try {
return invoke_on_others(smp_submit_to_options{}, std::move(func), std::move(args)...);
Expand Down Expand Up @@ -797,11 +801,10 @@ sharded<Service>::invoke_on_all(smp_submit_to_options options, std::function<fut
template <typename Service>
template <typename Func, typename... Args>
requires std::invocable<Func, Service&, internal::sharded_unwrap_t<Args>...>
&& std::is_same_v<futurize_t<std::invoke_result_t<Func, Service&, internal::sharded_unwrap_t<Args>...>>, future<>>
inline
future<>
sharded<Service>::invoke_on_all(smp_submit_to_options options, Func func, Args... args) noexcept {
static_assert(std::is_same_v<futurize_t<std::invoke_result_t<Func, Service&, internal::sharded_unwrap_t<Args>...>>, future<>>,
"invoke_on_all()'s func must return void or future<>");
try {
return invoke_on_all(options, invoke_on_multiple_func_type([func = std::move(func), args = std::tuple(std::move(args)...)] (Service& service) mutable {
return std::apply([&service, &func] (Args&&... args) mutable {
Expand All @@ -816,11 +819,10 @@ sharded<Service>::invoke_on_all(smp_submit_to_options options, Func func, Args..
template <typename Service>
template <typename Func, typename... Args>
requires std::invocable<Func, Service&, Args...>
&& std::is_same_v<futurize_t<std::invoke_result_t<Func, Service&, Args...>>, future<>>
inline
future<>
sharded<Service>::invoke_on_others(smp_submit_to_options options, Func func, Args... args) noexcept {
static_assert(std::is_same_v<futurize_t<std::invoke_result_t<Func, Service&, Args...>>, future<>>,
"invoke_on_others()'s func must return void or future<>");
try {
return invoke_on_all(options, [orig = this_shard_id(), func = std::move(func), args = std::tuple(std::move(args)...)] (Service& s) mutable -> future<> {
return this_shard_id() == orig ? make_ready_future<>() : futurize_apply(func, std::tuple_cat(std::forward_as_tuple(s), args));;
Expand Down