From: Jason Dillaman Date: Wed, 29 Apr 2020 16:27:46 +0000 (-0400) Subject: common: TokenBucketThrottle should use perfect forwarding for item X-Git-Tag: wip-pdonnell-testing-20200918.022351~1255^2~24 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=04df167b59f072f2aa913bea0b282115027f5505;p=ceph-ci.git common: TokenBucketThrottle should use perfect forwarding for item This will allow more than just a pointer to an item to be passed to the callback. Signed-off-by: Jason Dillaman --- diff --git a/src/common/Throttle.h b/src/common/Throttle.h index e38886de06d..d4bb77025af 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -414,16 +414,17 @@ public: return m_name; } - template - void add_blocker(uint64_t c, T *handler, I *item, uint64_t flag) { - Context *ctx = new LambdaContext([handler, item, flag](int r) { - (handler->*MF)(r, item, flag); + template + void add_blocker(uint64_t c, T&& t, MF&& mf, I&& item, uint64_t flag) { + auto ctx = new LambdaContext( + [t, mf, item=std::forward(item), flag](int) mutable { + (t->*mf)(std::forward(item), flag); }); m_blockers.emplace_back(c, ctx); } - template - bool get(uint64_t c, T *handler, I *item, uint64_t flag) { + template + bool get(uint64_t c, T&& t, MF&& mf, I&& item, uint64_t flag) { bool wait = false; uint64_t got = 0; std::lock_guard lock(m_lock); @@ -441,8 +442,10 @@ public: } } - if (wait) - add_blocker(c - got, handler, item, flag); + if (wait) { + add_blocker(c - got, std::forward(t), std::forward(mf), + std::forward(item), flag); + } return wait; } diff --git a/src/librbd/io/ImageRequestWQ.cc b/src/librbd/io/ImageRequestWQ.cc index 2d214184281..c8677d0a8c7 100644 --- a/src/librbd/io/ImageRequestWQ.cc +++ b/src/librbd/io/ImageRequestWQ.cc @@ -789,9 +789,10 @@ void ImageRequestWQ::apply_qos_limit(const uint64_t flag, } template -void ImageRequestWQ::handle_throttle_ready(int r, ImageDispatchSpec *item, uint64_t flag) { +void ImageRequestWQ::handle_throttle_ready( + ImageDispatchSpec *item, uint64_t flag) { CephContext *cct = m_image_ctx.cct; - ldout(cct, 15) << "r=" << r << ", " << "req=" << item << dendl; + ldout(cct, 15) << "req=" << item << dendl; ceph_assert(m_io_throttled.load() > 0); item->set_throttled(flag); @@ -821,9 +822,8 @@ bool ImageRequestWQ::needs_throttle(ImageDispatchSpec *item) { throttle = t.second; if (item->tokens_requested(flag, &tokens) && - throttle->get, ImageDispatchSpec, - &ImageRequestWQ::handle_throttle_ready>( - tokens, this, item, flag)) { + throttle->get(tokens, this, &ImageRequestWQ::handle_throttle_ready, + item, flag)) { blocked = true; } else { item->set_throttled(flag); diff --git a/src/librbd/io/ImageRequestWQ.h b/src/librbd/io/ImageRequestWQ.h index ecbf33f3d20..40acfa52390 100644 --- a/src/librbd/io/ImageRequestWQ.h +++ b/src/librbd/io/ImageRequestWQ.h @@ -158,7 +158,7 @@ private: void handle_refreshed(int r, ImageDispatchSpec *req); void handle_blocked_writes(int r); - void handle_throttle_ready(int r, ImageDispatchSpec *item, uint64_t flag); + void handle_throttle_ready(ImageDispatchSpec *item, uint64_t flag); }; } // namespace io