grpc
src
core
lib
resource_quota
thread_quota.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
15
#include <
grpc/support/port_platform.h
>
16
17
#include "
src/core/lib/resource_quota/thread_quota.h
"
18
19
#include <
grpc/support/log.h
>
20
21
namespace
grpc_core
{
22
23
ThreadQuota::ThreadQuota
() =
default
;
24
25
ThreadQuota::~ThreadQuota
() =
default
;
26
27
void
ThreadQuota::SetMax
(
size_t
new_max) {
28
MutexLock
lock(&
mu_
);
29
max_
= new_max;
30
}
31
32
bool
ThreadQuota::Reserve
(
size_t
num_threads
) {
33
MutexLock
lock(&
mu_
);
34
if
(allocated_ +
num_threads
>
max_
)
return
false
;
35
allocated_ +=
num_threads
;
36
return
true
;
37
}
38
39
void
ThreadQuota::Release
(
size_t
num_threads
) {
40
MutexLock
lock(&
mu_
);
41
GPR_ASSERT
(
num_threads
<= allocated_);
42
allocated_ -=
num_threads
;
43
}
44
45
}
// namespace grpc_core
log.h
grpc_core::ThreadQuota::mu_
Mutex mu_
Definition:
thread_quota.h:52
grpc_core
Definition:
call_metric_recorder.h:31
grpc_core::MutexLock
Definition:
src/core/lib/gprpp/sync.h:88
grpc_core::ThreadQuota::Release
void Release(size_t num_threads)
Definition:
thread_quota.cc:39
GPR_ASSERT
#define GPR_ASSERT(x)
Definition:
include/grpc/impl/codegen/log.h:94
grpc_core::ThreadQuota::ThreadQuota
ThreadQuota()
grpc_core::ThreadQuota::Reserve
bool Reserve(size_t num_threads)
Definition:
thread_quota.cc:32
grpc_core::ThreadQuota::~ThreadQuota
~ThreadQuota() override
num_threads
static volatile int num_threads
Definition:
benchmark-thread.c:30
grpc_core::ThreadQuota::SetMax
void SetMax(size_t new_max)
Definition:
thread_quota.cc:27
thread_quota.h
max_
const int max_
Definition:
bloaty/third_party/googletest/googlemock/src/gmock-cardinalities.cc:88
port_platform.h
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:36