]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: add ref header
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 17 Jul 2019 19:36:36 +0000 (12:36 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 19 Jul 2019 18:55:19 +0000 (11:55 -0700)
This enables the use of these handy ref templates outside of Message.h.
This is necessary for a future rework of #26348.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/common/ref.h [new file with mode: 0644]
src/msg/Message.h

diff --git a/src/common/ref.h b/src/common/ref.h
new file mode 100644 (file)
index 0000000..6f3f7fd
--- /dev/null
@@ -0,0 +1,26 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef COMMON_REF_H
+#define COMMON_REF_H
+
+#include <boost/intrusive_ptr.hpp>
+
+namespace ceph {
+template<typename T> using ref_t = boost::intrusive_ptr<T>;
+template<typename T> using cref_t = boost::intrusive_ptr<const T>;
+template<class T, class U>
+boost::intrusive_ptr<T> ref_cast(const boost::intrusive_ptr<U>& r) noexcept {
+  return static_cast<T*>(r.get());
+}
+template<class T, class U>
+boost::intrusive_ptr<T> ref_cast(boost::intrusive_ptr<U>&& r) noexcept {
+  return {static_cast<T*>(r.detach()), false};
+}
+template<class T, class U>
+boost::intrusive_ptr<const T> ref_cast(const boost::intrusive_ptr<const U>& r) noexcept {
+  return static_cast<const T*>(r.get());
+}
+}
+
+#endif
index 87b4b263b686de3ab83857a32010ae191c4e7158..dc3773663aeae46edd0eef7a60c8f0517fa73fd5 100644 (file)
@@ -25,6 +25,7 @@
 #include "common/RefCountedObj.h"
 #include "common/ThrottleInterface.h"
 #include "common/config.h"
+#include "common/ref.h"
 #include "common/debug.h"
 #include "common/zipkin_trace.h"
 #include "include/ceph_assert.h" // Because intrusive_ptr clobbers our assert...
@@ -519,22 +520,8 @@ private:
 };
 
 namespace ceph {
-template<typename T> using ref_t = boost::intrusive_ptr<T>;
-template<typename T> using cref_t = boost::intrusive_ptr<const T>;
-template<class T, class U>
-boost::intrusive_ptr<T> ref_cast(const boost::intrusive_ptr<U>& r) noexcept {
-  return static_cast<T*>(r.get());
-}
-template<class T, class U>
-boost::intrusive_ptr<T> ref_cast(boost::intrusive_ptr<U>&& r) noexcept {
-  return {static_cast<T*>(r.detach()), false};
-}
-template<class T, class U>
-boost::intrusive_ptr<const T> ref_cast(const boost::intrusive_ptr<const U>& r) noexcept {
-  return static_cast<const T*>(r.get());
-}
 template<class T, typename... Args>
-boost::intrusive_ptr<T> make_message(Args&&... args) {
+ceph::ref_t<T> make_message(Args&&... args) {
   return {new T(std::forward<Args>(args)...), false};
 }
 }