]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson: don't allocate exception_ptr when returning error code.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Sun, 15 Sep 2019 14:01:39 +0000 (16:01 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 20 Nov 2019 19:37:41 +0000 (20:37 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/common/errorator.h

index cee3e43db20f6efe2b00ce8b7d43d587e134f28d..55710106341fc64ad5d753c28d32f4274a24ef3f 100644 (file)
@@ -73,12 +73,19 @@ private:
 
   // implement the errorable interface
   struct throwable_carrier{};
+  static std::exception_ptr carrier_instance;
 
   static constexpr const std::type_info& exception_ptr_type_info() {
     return typeid(throwable_carrier);
   }
   auto to_exception_ptr() const {
-    return std::make_exception_ptr<throwable_carrier>({});
+    // error codes don't need to instantiate `std::exception_ptr` each
+    // time as the code is actually a part of the type itself.
+    // `std::make_exception_ptr()` on modern enough GCCs is quite cheap
+    // (see the Gleb Natapov's patch eradicating throw/catch there),
+    // but using one instance per type boils down the overhead to just
+    // ref-counting.
+    return carrier_instance;
   }
   static const auto& from_exception_ptr(std::exception_ptr) {
     return instance;
@@ -87,6 +94,11 @@ private:
   friend class error_t<unthrowable_wrapper<ErrorT, ErrorV>>;
 };
 
+template <class ErrorT, ErrorT ErrorV>
+std::exception_ptr unthrowable_wrapper<ErrorT, ErrorV>::carrier_instance = \
+  std::make_exception_ptr<
+    unthrowable_wrapper<ErrorT, ErrorV>::throwable_carrier>({});
+
 namespace _impl {
   template <class T> struct always_false : std::false_type {};
 };