]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/common,cmake: use seastar API Level 5
authorKefu Chai <kchai@redhat.com>
Wed, 9 Sep 2020 13:03:32 +0000 (21:03 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 10 Sep 2020 13:28:55 +0000 (21:28 +0800)
* cmake: bump Seastar_API_LEVEL to "5"
* errorator.h: add invoke() methods to futurize variants, as in seastar
  API level 5, the future's store type is now either monostate or
  a single T, instead of tuple. so it'd be simpler to integrate
  with seastar with invoke() semantic without the boxing-unboxing
  dance.
* errorator.h: drop apply() methods, as they are not used anymore.
* errorator.h: rename and revise tuple2future. as the store type
  is not tuple now, the trait's name is changed accordingly to
  match seastar::internal::future_stored_type

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/CMakeLists.txt
src/crimson/common/errorator.h

index 1f8628c8346ed34fa4d82cf1ddb6f94ac2202dac..38d33bac44ac9a1d8253cff5dbc534bc85b1d33d 100644 (file)
@@ -317,7 +317,7 @@ if(WITH_SEASTAR)
       _find_package(${ARGV})
     endif()
   endmacro ()
-  set(Seastar_API_LEVEL "4" CACHE STRING "" FORCE)
+  set(Seastar_API_LEVEL "5" CACHE STRING "" FORCE)
   set(Seastar_HWLOC OFF CACHE BOOL "" FORCE)
   set(Seastar_STD_OPTIONAL_VARIANT_STRINGVIEW ON CACHE BOOL "" FORCE)
   if(Seastar_DPDK)
index 450227d7806140e806f30eb725c888d55ffa8de9..dc36dfc37a0e01c6f5e1b01509e4ba9b11801935 100644 (file)
@@ -54,7 +54,7 @@ inline auto do_until(AsyncAction action) {
 
   while (true) {
     auto f = futurator::invoke(action);
-    if (!seastar::need_preempt() && f.available() && std::get<0>(f.get())) {
+    if (!seastar::need_preempt() && f.available() && f.get()) {
       return futurator::type::errorator_type::template make_ready_future<>();
     }
     if (!f.available() || seastar::need_preempt()) {
@@ -570,8 +570,8 @@ private:
             // solution here would be mark the `::get_available_state()`
             // as `protected` and use dedicated `get_value()` exactly as
             // `::then()` already does.
-            return futurator_t::apply(std::forward<ValueFuncT>(valfunc),
-                                      std::move(future).get());
+            return futurator_t::invoke(std::forward<ValueFuncT>(valfunc),
+                                       std::move(future).get());
           }
         });
     }
@@ -835,21 +835,36 @@ private:
   class futurize {
     using vanilla_futurize = seastar::futurize<T>;
 
-    template <class...>
-    struct tuple2future {};
-    template <class... Args>
-    struct tuple2future <std::tuple<Args...>> {
-      using type = future<Args...>;
+    template <class Stored, int Dummy = 0>
+    struct stored_to_future {
+      using type = future<Stored>;
+    };
+    template <int Dummy>
+    struct stored_to_future <seastar::internal::monostate, Dummy> {
+      using type = future<>;
     };
 
   public:
     using type =
-      typename tuple2future<typename vanilla_futurize::value_type>::type;
+      typename stored_to_future<typename vanilla_futurize::value_type>::type;
 
     template <class Func, class... Args>
-    static type apply(Func&& func, std::tuple<Args...>&& args) {
-      return vanilla_futurize::apply(std::forward<Func>(func),
-                                     std::forward<std::tuple<Args...>>(args));
+    static type invoke(Func&& func, Args&&... args) {
+      try {
+        return vanilla_futurize::invoke(std::forward<Func>(func),
+                                        std::forward<Args>(args)...);
+      } catch (...) {
+        return make_exception_future(std::current_exception());
+      }
+    }
+
+    template <class Func>
+    static type invoke(Func&& func, seastar::internal::monostate) {
+      try {
+        return vanilla_futurize::invoke(std::forward<Func>(func));
+      } catch (...) {
+        return make_exception_future(std::current_exception());
+      }
     }
 
     template <typename Arg>
@@ -876,6 +891,25 @@ private:
       }
     }
 
+    template <class Func, class... Args>
+    static type invoke(Func&& func, Args&&... args) {
+      try {
+        return ::seastar::futurize_invoke(std::forward<Func>(func),
+                                          std::forward<Args>(args)...);
+      } catch (...) {
+        return make_exception_future(std::current_exception());
+      }
+    }
+
+    template <class Func>
+    static type invoke(Func&& func, seastar::internal::monostate) {
+      try {
+        return ::seastar::futurize_invoke(std::forward<Func>(func));
+      } catch (...) {
+        return make_exception_future(std::current_exception());
+      }
+    }
+
     template <typename Arg>
     static type make_exception_future(Arg&& arg) {
       return ::crimson::errorator<AllowedErrors...>::make_exception_future2<ValuesT...>(std::forward<Arg>(arg));
@@ -1044,16 +1078,6 @@ struct futurize<Container<::crimson::errorated_future_marker<Values...>>> {
 
   template<typename Func, typename... FuncArgs>
   [[gnu::always_inline]]
-  static inline type apply(Func&& func, std::tuple<FuncArgs...>&& args) noexcept {
-    try {
-      return std::apply(std::forward<Func>(func),
-                        std::forward<std::tuple<FuncArgs...>>(args));
-    } catch (...) {
-      return make_exception_future(std::current_exception());
-    }
-  }
-
-  template<typename Func, typename... FuncArgs>
   static inline type invoke(Func&& func, FuncArgs&&... args) noexcept {
     try {
         return func(std::forward<FuncArgs>(args)...);