From: Jason Dillaman Date: Fri, 17 Apr 2020 14:02:10 +0000 (-0400) Subject: common: add helper C_TrackerOp context class X-Git-Tag: v14.2.22~1^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=476b718e9b201a68a3fada1117542f14ee2620a8;p=ceph.git common: add helper C_TrackerOp context class This wraps the functionality of starting and finishing a tracked op into the standard context interface. Signed-off-by: Jason Dillaman (cherry picked from commit 4bd9d1501f3832206ef12155cec3f008e3160822) --- diff --git a/src/common/AsyncOpTracker.h b/src/common/AsyncOpTracker.h index d913032aa56a..dfa913ad4a3a 100644 --- a/src/common/AsyncOpTracker.h +++ b/src/common/AsyncOpTracker.h @@ -5,8 +5,7 @@ #define CEPH_ASYNC_OP_TRACKER_H #include "common/ceph_mutex.h" - -struct Context; +#include "include/Context.h" class AsyncOpTracker { public: @@ -27,4 +26,23 @@ private: }; +class C_TrackedOp : public Context { +public: + C_TrackedOp(AsyncOpTracker& async_op_tracker, Context* on_finish) + : m_async_op_tracker(async_op_tracker), m_on_finish(on_finish) { + m_async_op_tracker.start_op(); + } + + void finish(int r) override { + if (m_on_finish != nullptr) { + m_on_finish->complete(r); + } + m_async_op_tracker.finish_op(); + } + +private: + AsyncOpTracker& m_async_op_tracker; + Context* m_on_finish; +}; + #endif // CEPH_ASYNC_OP_TRACKER_H