From 8f7cf9375e217c5e59f45baf3fc2a92b4bc9a929 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 12 Jan 2016 20:33:22 -0500 Subject: [PATCH] WorkQueue: delay registering PointerWQ with thread pool Derived classes should be responsible for registration to avoid accessing a partially constructed object. Signed-off-by: Jason Dillaman --- src/common/WorkQueue.h | 8 ++++---- src/librbd/AioImageRequestWQ.cc | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/WorkQueue.h b/src/common/WorkQueue.h index a6e7972408f62..5103cdd0f0054 100644 --- a/src/common/WorkQueue.h +++ b/src/common/WorkQueue.h @@ -353,10 +353,6 @@ public: template class PointerWQ : public WorkQueue_ { public: - PointerWQ(string n, time_t ti, time_t sti, ThreadPool* p) - : WorkQueue_(n, ti, sti), m_pool(p), m_processing(0) { - m_pool->add_work_queue(this); - } ~PointerWQ() { m_pool->remove_work_queue(this); assert(m_processing == 0); @@ -382,6 +378,9 @@ public: return _empty(); } protected: + PointerWQ(string n, time_t ti, time_t sti, ThreadPool* p) + : WorkQueue_(n, ti, sti), m_pool(p), m_processing(0) { + } virtual void _clear() { assert(m_pool->_lock.is_locked()); m_items.clear(); @@ -579,6 +578,7 @@ public: ContextWQ(const string &name, time_t ti, ThreadPool *tp) : ThreadPool::PointerWQ(name, ti, 0, tp), m_lock("ContextWQ::m_lock") { + tp->add_work_queue(this); } void queue(Context *ctx, int result = 0) { diff --git a/src/librbd/AioImageRequestWQ.cc b/src/librbd/AioImageRequestWQ.cc index 9871bb0535ef4..f8efe0df6234b 100644 --- a/src/librbd/AioImageRequestWQ.cc +++ b/src/librbd/AioImageRequestWQ.cc @@ -27,6 +27,7 @@ AioImageRequestWQ::AioImageRequestWQ(ImageCtx *image_ctx, const string &name, m_shutdown(false), m_on_shutdown(nullptr) { CephContext *cct = m_image_ctx.cct; ldout(cct, 5) << this << " " << ": ictx=" << image_ctx << dendl; + tp->add_work_queue(this); } ssize_t AioImageRequestWQ::read(uint64_t off, uint64_t len, char *buf, -- 2.39.5