From 46971e49806be7ba0750a0e81243fd54e4ed9444 Mon Sep 17 00:00:00 2001 From: shangdehao1 Date: Mon, 18 Feb 2019 04:30:28 +0800 Subject: [PATCH] tools: templatize create_rados_callback Also cleanup unused template codes Signed-off-by: Dehao Shang --- .../immutable_object_cache/CMakeLists.txt | 1 - src/tools/immutable_object_cache/Utils.cc | 18 ---- src/tools/immutable_object_cache/Utils.h | 83 +------------------ 3 files changed, 1 insertion(+), 101 deletions(-) delete mode 100644 src/tools/immutable_object_cache/Utils.cc diff --git a/src/tools/immutable_object_cache/CMakeLists.txt b/src/tools/immutable_object_cache/CMakeLists.txt index f4c165b95a2ca..56a5f73109cf4 100644 --- a/src/tools/immutable_object_cache/CMakeLists.txt +++ b/src/tools/immutable_object_cache/CMakeLists.txt @@ -5,7 +5,6 @@ set(ceph_immutable_object_cache_files CacheClient.cc CacheSession.cc SimplePolicy.cc - Utils.cc Types.cc ) add_library(ceph_immutable_object_cache_lib STATIC ${ceph_immutable_object_cache_files}) diff --git a/src/tools/immutable_object_cache/Utils.cc b/src/tools/immutable_object_cache/Utils.cc deleted file mode 100644 index 28b9b0b1d10c0..0000000000000 --- a/src/tools/immutable_object_cache/Utils.cc +++ /dev/null @@ -1,18 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab - -#include "Utils.h" - -#define dout_subsys ceph_subsys_immutable_obj_cache -#undef dout_prefix -#define dout_prefix *_dout << "ceph::cache::Utils: " << __func__ << ": " - -namespace ceph { -namespace immutable_obj_cache { - -librados::AioCompletion *create_rados_callback(Context *on_finish) { - return create_rados_callback(on_finish); -} - -} // namespace immutable_obj_cache -} // namespace ceph diff --git a/src/tools/immutable_object_cache/Utils.h b/src/tools/immutable_object_cache/Utils.h index d3fb8d92cd46b..daa2bffda8bf9 100644 --- a/src/tools/immutable_object_cache/Utils.h +++ b/src/tools/immutable_object_cache/Utils.h @@ -12,11 +12,6 @@ namespace ceph { namespace immutable_obj_cache { namespace detail { -template -void rados_callback(rados_completion_t c, void *arg) { - reinterpret_cast(arg)->complete(rados_aio_get_return_value(c)); -} - template void rados_callback(rados_completion_t c, void *arg) { T *obj = reinterpret_cast(arg); @@ -24,90 +19,14 @@ void rados_callback(rados_completion_t c, void *arg) { (obj->*MF)(r); } -template -void rados_state_callback(rados_completion_t c, void *arg) { - T *obj = reinterpret_cast(arg); - int r = rados_aio_get_return_value(c); - Context *on_finish = (obj->*MF)(&r); - if (on_finish != nullptr) { - on_finish->complete(r); - if (destroy) { - delete obj; - } - } -} - -template -class C_CallbackAdapter : public Context { - T *obj; -public: - C_CallbackAdapter(T *obj) : obj(obj) { - } - -protected: - void finish(int r) override { - (obj->*MF)(r); - } -}; - -template -class C_StateCallbackAdapter : public Context { - T *obj; -public: - C_StateCallbackAdapter(T *obj) : obj(obj){ - } - -protected: - void complete(int r) override { - Context *on_finish = (obj->*MF)(&r); - if (on_finish != nullptr) { - on_finish->complete(r); - if (destroy) { - delete obj; - } - } - Context::complete(r); - } - void finish(int r) override { - } -}; - -template -struct C_AsyncCallback : public Context { - WQ *op_work_queue; - Context *on_finish; - - C_AsyncCallback(WQ *op_work_queue, Context *on_finish) - : op_work_queue(op_work_queue), on_finish(on_finish) { - } - void finish(int r) override { - op_work_queue->queue(on_finish, r); - } -}; - } // namespace detail - -librados::AioCompletion *create_rados_callback(Context *on_finish); - -template -librados::AioCompletion *create_rados_callback(T *obj) { - return librados::Rados::aio_create_completion( - obj, &detail::rados_callback, nullptr); -} - -template +template librados::AioCompletion *create_rados_callback(T *obj) { return librados::Rados::aio_create_completion( obj, &detail::rados_callback, nullptr); } -template -librados::AioCompletion *create_rados_callback(T *obj) { - return librados::Rados::aio_create_completion( - obj, &detail::rados_state_callback, nullptr); -} - } // namespace immutable_obj_cache } // namespace ceph #endif -- 2.39.5