api.cc
Go to the documentation of this file.
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 
16 
18 
19 #include <stdint.h>
20 
21 #include <atomic>
22 #include <memory>
23 #include <string>
24 #include <utility>
25 
26 #include "absl/strings/str_cat.h"
27 
28 #include <grpc/grpc.h>
29 
37 
38 namespace grpc_core {
39 
41  const grpc_channel_args* args) {
42  return grpc_channel_args_find_pointer<ResourceQuota>(args,
44  ->Ref();
45 }
46 
48  if (args.GetObject<ResourceQuota>() != nullptr) return args;
49  // If there's no existing quota, add it to the default one - shared between
50  // all channel args declared thusly. This prevents us from accidentally not
51  // sharing subchannels due to their channel args not specifying a quota.
52  return args.SetObject(ResourceQuota::Default());
53 }
54 
56  builder->channel_args_preconditioning()->RegisterStage(
58 }
59 
60 } // namespace grpc_core
61 
64 }
65 
67  static std::atomic<uintptr_t> anonymous_counter{0};
68  std::string quota_name =
69  name == nullptr
70  ? absl::StrCat("anonymous-quota-", anonymous_counter.fetch_add(1))
71  : name;
72  return (new grpc_core::ResourceQuota(std::move(quota_name)))->c_ptr();
73 }
74 
77 }
78 
81 }
82 
84  size_t new_size) {
87  ->memory_quota()
88  ->SetSize(new_size);
89 }
90 
92  grpc_resource_quota* resource_quota, int new_max_threads) {
94  ->thread_quota()
95  ->SetMax(new_max_threads);
96 }
grpc_resource_quota_unref
void grpc_resource_quota_unref(grpc_resource_quota *resource_quota)
Definition: api.cc:79
absl::StrCat
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: abseil-cpp/absl/strings/str_cat.cc:98
grpc_resource_quota
struct grpc_resource_quota grpc_resource_quota
Definition: grpc_types.h:729
grpc_core
Definition: call_metric_recorder.h:31
GRPC_ARG_RESOURCE_QUOTA
#define GRPC_ARG_RESOURCE_QUOTA
Definition: grpc_types.h:299
grpc_core::CoreConfiguration::Builder
Definition: core_configuration.h:41
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
binary_size.new_size
def new_size
Definition: binary_size.py:124
setup.name
name
Definition: setup.py:542
grpc_core::RefCountedPtr::release
T * release()
Definition: ref_counted_ptr.h:140
grpc_arg_pointer_vtable
Definition: grpc_types.h:85
grpc_channel_args
Definition: grpc_types.h:132
resource_quota
ResourceQuotaRefPtr resource_quota
Definition: filter_fuzzer.cc:145
channel_args_preconditioning.h
grpc_resource_quota_set_max_threads
void grpc_resource_quota_set_max_threads(grpc_resource_quota *resource_quota, int new_max_threads)
Definition: api.cc:91
grpc_core::ResourceQuota
Definition: src/core/lib/resource_quota/resource_quota.h:40
grpc_core::RefCounted::Unref
void Unref()
Definition: ref_counted.h:302
profile_analyzer.builder
builder
Definition: profile_analyzer.py:159
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::ChannelArgTypeTraits
Definition: channel_args.h:60
grpc_core::ResourceQuota::thread_quota
const RefCountedPtr< ThreadQuota > & thread_quota()
Definition: src/core/lib/resource_quota/resource_quota.h:53
grpc.h
grpc_resource_quota_ref
void grpc_resource_quota_ref(grpc_resource_quota *resource_quota)
Definition: api.cc:75
grpc_core::ResourceQuota::memory_quota
MemoryQuotaRefPtr memory_quota()
Definition: src/core/lib/resource_quota/resource_quota.h:51
grpc_resource_quota_create
grpc_resource_quota * grpc_resource_quota_create(const char *name)
Definition: api.cc:66
grpc_core::ResourceQuota::Default
static ResourceQuotaRefPtr Default()
Definition: resource_quota.cc:27
resource_quota.h
grpc_core::ExecCtx
Definition: exec_ctx.h:97
stdint.h
grpc_core::RegisterResourceQuota
void RegisterResourceQuota(CoreConfiguration::Builder *builder)
Definition: api.cc:55
grpc_resource_quota_resize
void grpc_resource_quota_resize(grpc_resource_quota *resource_quota, size_t new_size)
Definition: api.cc:83
grpc_core::ResourceQuotaFromChannelArgs
ResourceQuotaRefPtr ResourceQuotaFromChannelArgs(const grpc_channel_args *args)
Definition: api.cc:40
exec_ctx
grpc_core::ExecCtx exec_ctx
Definition: end2end_binder_transport_test.cc:75
exec_ctx.h
grpc_core::ChannelArgs
Definition: channel_args.h:111
ref_counted_ptr.h
memory_quota.h
grpc_core::EnsureResourceQuotaInChannelArgs
ChannelArgs EnsureResourceQuotaInChannelArgs(ChannelArgs args)
Definition: api.cc:47
channel_args.h
grpc_resource_quota_arg_vtable
const grpc_arg_pointer_vtable * grpc_resource_quota_arg_vtable()
Definition: api.cc:62
thread_quota.h
grpc_core::CppImplOf< ResourceQuota, grpc_resource_quota >::FromC
static ResourceQuota * FromC(grpc_resource_quota *c_type)
Definition: cpp_impl_of.h:30
grpc_core::RefCounted::Ref
RefCountedPtr< Child > Ref() GRPC_MUST_USE_RESULT
Definition: ref_counted.h:287
api.h
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:31