From: Jason Dillaman Date: Fri, 17 Apr 2020 14:02:10 +0000 (-0400) Subject: common: add helper C_TrackerOp context class X-Git-Tag: v17.0.0~2598^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=4bd9d1501f3832206ef12155cec3f008e3160822;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 --- diff --git a/src/common/AsyncOpTracker.h b/src/common/AsyncOpTracker.h index d913032aa56a0..dfa913ad4a3a0 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