]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/common/throttle.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crimson / common / throttle.h
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>
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>
10
11 #include "common/ThrottleInterface.h"
12
13 namespace crimson::common {
14
15 class Throttle final : public ThrottleInterface {
16 size_t max = 0;
17 size_t count = 0;
18 size_t pending = 0;
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 }
35 size_t get_pending() const {
36 return pending;
37 }
38 void reset_max(size_t m);
39 private:
40 bool _should_wait(size_t c) const;
41 };
42
43 } // namespace crimson::common