]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #pragma once | |
5 | ||
6 | #include <seastar/core/condition-variable.hh> | |
9f95a23c TL |
7 | // pull seastar::timer<...>::timer definitions. FIX SEASTAR or reactor.hh |
8 | // is obligatory and should be included everywhere? | |
9 | #include <seastar/core/reactor.hh> | |
11fdf7f2 TL |
10 | |
11 | #include "common/ThrottleInterface.h" | |
12 | ||
f67539c2 | 13 | namespace crimson::common { |
11fdf7f2 TL |
14 | |
15 | class Throttle final : public ThrottleInterface { | |
16 | size_t max = 0; | |
17 | size_t count = 0; | |
1e59de90 | 18 | size_t pending = 0; |
11fdf7f2 TL |
19 | // we cannot change the "count" of seastar::semaphore after it is created, |
20 | // so use condition_variable instead. | |
21 | seastar::condition_variable on_free_slots; | |
22 | public: | |
23 | explicit Throttle(size_t m) | |
24 | : max(m) | |
25 | {} | |
26 | int64_t take(int64_t c = 1) override; | |
27 | int64_t put(int64_t c = 1) override; | |
28 | seastar::future<> get(size_t c); | |
29 | size_t get_current() const { | |
30 | return count; | |
31 | } | |
32 | size_t get_max() const { | |
33 | return max; | |
34 | } | |
1e59de90 TL |
35 | size_t get_pending() const { |
36 | return pending; | |
37 | } | |
11fdf7f2 TL |
38 | void reset_max(size_t m); |
39 | private: | |
40 | bool _should_wait(size_t c) const; | |
41 | }; | |
42 | ||
f67539c2 | 43 | } // namespace crimson::common |