From ca5ac3a7f5e7e2c70cf3cacf0d7c15bdd47eba28 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 17 Jul 2019 12:36:36 -0700 Subject: [PATCH] common: add ref header 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 --- src/common/ref.h | 26 ++++++++++++++++++++++++++ src/msg/Message.h | 17 ++--------------- 2 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 src/common/ref.h diff --git a/src/common/ref.h b/src/common/ref.h new file mode 100644 index 00000000000..6f3f7fd0b03 --- /dev/null +++ b/src/common/ref.h @@ -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 + +namespace ceph { +template using ref_t = boost::intrusive_ptr; +template using cref_t = boost::intrusive_ptr; +template +boost::intrusive_ptr ref_cast(const boost::intrusive_ptr& r) noexcept { + return static_cast(r.get()); +} +template +boost::intrusive_ptr ref_cast(boost::intrusive_ptr&& r) noexcept { + return {static_cast(r.detach()), false}; +} +template +boost::intrusive_ptr ref_cast(const boost::intrusive_ptr& r) noexcept { + return static_cast(r.get()); +} +} + +#endif diff --git a/src/msg/Message.h b/src/msg/Message.h index 87b4b263b68..dc3773663ae 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -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 using ref_t = boost::intrusive_ptr; -template using cref_t = boost::intrusive_ptr; -template -boost::intrusive_ptr ref_cast(const boost::intrusive_ptr& r) noexcept { - return static_cast(r.get()); -} -template -boost::intrusive_ptr ref_cast(boost::intrusive_ptr&& r) noexcept { - return {static_cast(r.detach()), false}; -} -template -boost::intrusive_ptr ref_cast(const boost::intrusive_ptr& r) noexcept { - return static_cast(r.get()); -} template -boost::intrusive_ptr make_message(Args&&... args) { +ceph::ref_t make_message(Args&&... args) { return {new T(std::forward(args)...), false}; } } -- 2.39.5