Debian Codegraph @

src/core/lib/resource_quota/resource_quota.h

raw
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef GRPC_CORE_LIB_RESOURCE_QUOTA_RESOURCE_QUOTA_H
16 #define GRPC_CORE_LIB_RESOURCE_QUOTA_RESOURCE_QUOTA_H
17
18 #include <grpc/support/port_platform.h>
19
20 #include <string>
21 #include <utility>
22
23 #include "absl/strings/string_view.h"
24
25 #include <grpc/impl/codegen/grpc_types.h>
26
27 #include "src/core/lib/gpr/useful.h"
28 #include "src/core/lib/gprpp/cpp_impl_of.h"
29 #include "src/core/lib/gprpp/ref_counted.h"
30 #include "src/core/lib/gprpp/ref_counted_ptr.h"
31 #include "src/core/lib/resource_quota/memory_quota.h"
32 #include "src/core/lib/resource_quota/thread_quota.h"
33
34 namespace grpc_core {
35
36 class ResourceQuota;
37
38 using ResourceQuotaRefPtr = RefCountedPtr<ResourceQuota>;
39
40 class ResourceQuota : public RefCounted<ResourceQuota>,
41 public CppImplOf<ResourceQuota, grpc_resource_quota> {
42 public:
43 explicit ResourceQuota(std::string name);
44 ~ResourceQuota() override;
45
46 ResourceQuota(const ResourceQuota&) = delete;
47 ResourceQuota& operator=(const ResourceQuota&) = delete;
48
49 static absl::string_view ChannelArgName() { return GRPC_ARG_RESOURCE_QUOTA; }
50
51 MemoryQuotaRefPtr memory_quota() { return memory_quota_; }
52
53 const RefCountedPtr<ThreadQuota>& thread_quota() { return thread_quota_; }
54
55 // The default global resource quota
56 static ResourceQuotaRefPtr Default();
57
58 static int ChannelArgsCompare(const ResourceQuota* a,
59 const ResourceQuota* b) {
60 return QsortCompare(a, b);
61 }
62
63 private:
64 MemoryQuotaRefPtr memory_quota_;
65 RefCountedPtr<ThreadQuota> thread_quota_;
66 };
67
68 inline ResourceQuotaRefPtr MakeResourceQuota(std::string name) {
69 return MakeRefCounted<ResourceQuota>(std::move(name));
70 }
71
72 } // namespace grpc_core
73
74 #endif // GRPC_CORE_LIB_RESOURCE_QUOTA_RESOURCE_QUOTA_H