@@ -300,34 +300,6 @@ class OperationThrottler : public BlockerT<OperationThrottler>,
300300 friend BlockerT<OperationThrottler>;
301301 static constexpr const char * type_name = " OperationThrottler" ;
302302
303- template <typename OperationT, typename F>
304- auto with_throttle (
305- OperationT* op,
306- crimson::osd::scheduler::params_t params,
307- F &&f) {
308- if (!max_in_progress) return f ();
309- return acquire_throttle (params)
310- .then (std::forward<F>(f))
311- .then ([this ](auto x) {
312- release_throttle ();
313- return x;
314- });
315- }
316-
317- template <typename OperationT, typename F>
318- seastar::future<> with_throttle_while (
319- OperationT* op,
320- crimson::osd::scheduler::params_t params,
321- F &&f) {
322- return with_throttle (op, params, f).then ([this , params, op, f](bool cont) {
323- return cont
324- ? seastar::yield ().then ([params, op, f, this ] {
325- return with_throttle_while (op, params, f); })
326- : seastar::now ();
327- });
328- }
329-
330-
331303public:
332304 OperationThrottler (ConfigProxy &conf);
333305
@@ -340,24 +312,28 @@ class OperationThrottler : public BlockerT<OperationThrottler>,
340312 return !max_in_progress || in_progress < max_in_progress;
341313 }
342314
343- template <typename F>
344- auto with_throttle (
345- crimson::osd::scheduler::params_t params,
346- F &&f) {
347- if (!max_in_progress) return f ();
348- return acquire_throttle (params)
349- .then (std::forward<F>(f))
350- .finally ([this ] {
351- release_throttle ();
352- });
353- }
315+ class ThrottleReleaser {
316+ OperationThrottler *parent = nullptr ;
317+ public:
318+ ThrottleReleaser (OperationThrottler *parent) : parent(parent) {}
319+ ThrottleReleaser (const ThrottleReleaser &) = delete ;
320+ ThrottleReleaser (ThrottleReleaser &&rhs) noexcept {
321+ std::swap (parent, rhs.parent );
322+ }
354323
355- template <class OpT , class ... Args>
356- seastar::future<> with_throttle_while (
357- BlockingEvent::Trigger<OpT>&& trigger,
358- Args&&... args) {
359- return trigger.maybe_record_blocking (
360- with_throttle_while (std::forward<Args>(args)...), *this );
324+ ~ThrottleReleaser () {
325+ if (parent) {
326+ parent->release_throttle ();
327+ }
328+ }
329+ };
330+
331+ auto get_throttle (crimson::osd::scheduler::params_t params) {
332+ return acquire_throttle (
333+ params
334+ ).then ([this ] {
335+ return ThrottleReleaser{this };
336+ });
361337 }
362338
363339private:
0 commit comments