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: seperate invoke_on decls from defs #2470

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
151 changes: 93 additions & 58 deletions include/seastar/core/sharded.hh
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,7 @@ public:
/// the message.
/// Passes the default \ref smp_submit_to_options to the
/// \ref smp::submit_to() called behind the scenes.
future<> invoke_on_all(std::function<future<> (Service&)> func) noexcept {
try {
return invoke_on_all(smp_submit_to_options{}, std::move(func));
} catch (...) {
return current_exception_as_future();
}
}
future<> invoke_on_all(std::function<future<> (Service&)> func) noexcept;

/// Invoke a function on all instances of `Service`.
/// The return value becomes ready when all instances have processed
Expand Down Expand Up @@ -302,13 +296,7 @@ public:
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)...);
} catch (...) {
return current_exception_as_future();
}
}
future<> invoke_on_all(Func func, Args... args) noexcept;

/// Invoke a callable on all instances of \c Service except the instance
/// which is allocated on current shard.
Expand Down Expand Up @@ -339,13 +327,37 @@ public:
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)...);
} catch (...) {
return current_exception_as_future();
}
}
future<> invoke_on_others(Func func, Args... args) noexcept;

/// Invoke a callable on a specific instance of `Service`.
///
/// \param id shard id to call
/// \param options the options to forward to the \ref smp::submit_to()
/// called behind the scenes.
/// \param func a callable with signature `Value (Service&, Args...)` or
/// `future<Value> (Service&, Args...)` (for some `Value` type), or a pointer
/// to a member function of Service
/// \param args parameters to the callable; will be copied or moved. To pass by reference,
/// use std::ref().
///
/// \return result of calling `func(instance)` on the designated instance
template <typename Func, typename... Args, typename Ret = futurize_t<std::invoke_result_t<Func, Service&, Args...>>>
requires std::invocable<Func, Service&, Args&&...>
Ret
invoke_on(unsigned id, smp_submit_to_options options, Func&& func, Args&&... args);

/// Invoke a callable on a specific instance of `Service`.
///
/// \param id shard id to call
/// \param func a callable with signature `Value (Service&)` or
/// `future<Value> (Service&)` (for some `Value` type), or a pointer
/// to a member function of Service
/// \param args parameters to the callable
/// \return result of calling `func(instance)` on the designated instance
template <typename Func, typename... Args, typename Ret = futurize_t<std::invoke_result_t<Func, Service&, Args&&...>>>
requires std::invocable<Func, Service&, Args&&...>
Ret
invoke_on(unsigned id, Func&& func, Args&&... args);

/// Invoke a callable on a range of instances of `Service`.
///
Expand Down Expand Up @@ -496,43 +508,6 @@ public:
});
}

/// Invoke a callable on a specific instance of `Service`.
///
/// \param id shard id to call
/// \param options the options to forward to the \ref smp::submit_to()
/// called behind the scenes.
/// \param func a callable with signature `Value (Service&, Args...)` or
/// `future<Value> (Service&, Args...)` (for some `Value` type), or a pointer
/// to a member function of Service
/// \param args parameters to the callable; will be copied or moved. To pass by reference,
/// use std::ref().
///
/// \return result of calling `func(instance)` on the designated instance
template <typename Func, typename... Args, typename Ret = futurize_t<std::invoke_result_t<Func, Service&, Args...>>>
requires std::invocable<Func, Service&, Args&&...>
Ret
invoke_on(unsigned id, smp_submit_to_options options, Func&& func, Args&&... args) {
return smp::submit_to(id, options, [this, func = std::forward<Func>(func), args = std::tuple(std::move(args)...)] () mutable {
auto inst = get_local_service();
return std::apply(std::forward<Func>(func), std::tuple_cat(std::forward_as_tuple(*inst), std::move(args)));
});
}

/// Invoke a callable on a specific instance of `Service`.
///
/// \param id shard id to call
/// \param func a callable with signature `Value (Service&)` or
/// `future<Value> (Service&)` (for some `Value` type), or a pointer
/// to a member function of Service
/// \param args parameters to the callable
/// \return result of calling `func(instance)` on the designated instance
template <typename Func, typename... Args, typename Ret = futurize_t<std::invoke_result_t<Func, Service&, Args&&...>>>
requires std::invocable<Func, Service&, Args&&...>
Ret
invoke_on(unsigned id, Func&& func, Args&&... args) {
return invoke_on(id, smp_submit_to_options(), std::forward<Func>(func), std::forward<Args>(args)...);
}

/// Gets a reference to the local instance.
const Service& local() const noexcept;

Expand Down Expand Up @@ -797,6 +772,17 @@ sharded<Service>::invoke_on_all(smp_submit_to_options options, std::function<fut
}
}

template <typename Service>
inline
future<>
sharded<Service>::invoke_on_all(std::function<future<> (Service&)> func) noexcept {
try {
return invoke_on_all(smp_submit_to_options{}, std::move(func));
} catch (...) {
return current_exception_as_future();
}
}

template <typename Service>
template <typename Func, typename... Args>
requires std::invocable<Func, Service&, internal::sharded_unwrap_t<Args>...>
Expand All @@ -815,6 +801,20 @@ 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&, 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(Func func, Args... args) noexcept {
try {
return invoke_on_all(smp_submit_to_options{}, std::move(func), std::move(args)...);
} catch (...) {
return current_exception_as_future();
}
}

template <typename Service>
template <typename Func, typename... Args>
requires std::invocable<Func, Service&, Args...>
Expand All @@ -831,6 +831,41 @@ sharded<Service>::invoke_on_others(smp_submit_to_options options, Func func, Arg
}
}

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(Func func, Args... args) noexcept {
try {
return invoke_on_others(smp_submit_to_options{}, std::move(func), std::move(args)...);
} catch (...) {
return current_exception_as_future();
}
}

template <typename Service>
template <typename Func, typename... Args, typename Ret>
requires std::invocable<Func, Service&, Args&&...>
inline
Ret
sharded<Service>::invoke_on(unsigned id, smp_submit_to_options options, Func&& func, Args&&... args) {
return smp::submit_to(id, options, [this, func = std::forward<Func>(func), args = std::tuple(std::move(args)...)] () mutable {
auto inst = get_local_service();
return std::apply(std::forward<Func>(func), std::tuple_cat(std::forward_as_tuple(*inst), std::move(args)));
});
}

template <typename Service>
template <typename Func, typename... Args, typename Ret>
requires std::invocable<Func, Service&, Args&&...>
inline
Ret
sharded<Service>::invoke_on(unsigned id, Func&& func, Args&&... args) {
return invoke_on(id, smp_submit_to_options(), std::forward<Func>(func), std::forward<Args>(args)...);
}

template <typename Service>
template <typename R, typename Func, typename... Args>
requires std::invocable<Func, Service&, Args...>
Expand Down