Skip to content

Commit

Permalink
alien: be compatible use API Level 5
Browse files Browse the repository at this point in the history
in API level 5, internal::monostate is used to represent the state
of the return value of a function which returns "void", and tuple
is not used for passing the return value anymore. so in this
change, alien is updated to follow this convention and accept
futurize<>::value_type instead of futurize<>::tuple_type, otherwise
the alien appication fails to compile if API Level 5 is enabled, in that
case, instance of type T or internal::monostate is passed to
return_type_of::set() as the second parameter, and compile chokes
at seeing this.

Signed-off-by: Kefu Chai <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
tchaikov authored and avikivity committed Sep 13, 2020
1 parent 8933f76 commit 2b392de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 10 additions & 5 deletions include/seastar/core/alien.hh
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,26 @@ void run_on(unsigned shard, Func func) {

namespace internal {
template<typename Func>
using return_tuple_t = typename futurize<std::result_of_t<Func()>>::tuple_type;
using return_value_t = typename futurize<std::invoke_result_t<Func>>::value_type;

template<typename Func,
bool = std::is_empty<return_tuple_t<Func>>::value>
bool = std::is_empty_v<return_value_t<Func>>>
struct return_type_of {
using type = void;
static void set(std::promise<void>& p, std::tuple<>&&) {
static void set(std::promise<void>& p, return_value_t<Func>&&) {
p.set_value();
}
};
template<typename Func>
struct return_type_of<Func, false> {
using type = std::tuple_element_t<0, return_tuple_t<Func>>;
static void set(std::promise<type>& p, std::tuple<type>&& t) {
using return_tuple_t = typename futurize<std::invoke_result_t<Func>>::tuple_type;
using type = std::tuple_element_t<0, return_tuple_t>;
static void set(std::promise<type>& p, return_value_t<Func>&& t) {
#if SEASTAR_API_LEVEL < 5
p.set_value(std::get<0>(std::move(t)));
#else
p.set_value(std::move(t));
#endif
}
};
template <typename Func> using return_type_t = typename return_type_of<Func>::type;
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/alien_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ int main(int argc, char** argv)
return seastar::make_ready_future<int>(i);
}));
}
// std::future<void>
alien::submit_to(0, [] {
return seastar::make_ready_future<>();
}).wait();
int total = 0;
for (auto& count : counts) {
total += count.get();
Expand Down

0 comments on commit 2b392de

Please sign in to comment.