1*cc02d7e2SAndroid Build Coastguard Worker // 2*cc02d7e2SAndroid Build Coastguard Worker // 3*cc02d7e2SAndroid Build Coastguard Worker // Copyright 2016 gRPC authors. 4*cc02d7e2SAndroid Build Coastguard Worker // 5*cc02d7e2SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 6*cc02d7e2SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 7*cc02d7e2SAndroid Build Coastguard Worker // You may obtain a copy of the License at 8*cc02d7e2SAndroid Build Coastguard Worker // 9*cc02d7e2SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 10*cc02d7e2SAndroid Build Coastguard Worker // 11*cc02d7e2SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 12*cc02d7e2SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 13*cc02d7e2SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*cc02d7e2SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 15*cc02d7e2SAndroid Build Coastguard Worker // limitations under the License. 16*cc02d7e2SAndroid Build Coastguard Worker // 17*cc02d7e2SAndroid Build Coastguard Worker // 18*cc02d7e2SAndroid Build Coastguard Worker 19*cc02d7e2SAndroid Build Coastguard Worker #ifndef GRPCPP_RESOURCE_QUOTA_H 20*cc02d7e2SAndroid Build Coastguard Worker #define GRPCPP_RESOURCE_QUOTA_H 21*cc02d7e2SAndroid Build Coastguard Worker 22*cc02d7e2SAndroid Build Coastguard Worker struct grpc_resource_quota; 23*cc02d7e2SAndroid Build Coastguard Worker 24*cc02d7e2SAndroid Build Coastguard Worker #include <grpcpp/impl/grpc_library.h> 25*cc02d7e2SAndroid Build Coastguard Worker #include <grpcpp/support/config.h> 26*cc02d7e2SAndroid Build Coastguard Worker 27*cc02d7e2SAndroid Build Coastguard Worker namespace grpc { 28*cc02d7e2SAndroid Build Coastguard Worker 29*cc02d7e2SAndroid Build Coastguard Worker /// ResourceQuota represents a bound on memory and thread usage by the gRPC 30*cc02d7e2SAndroid Build Coastguard Worker /// library. A ResourceQuota can be attached to a server (via \a ServerBuilder), 31*cc02d7e2SAndroid Build Coastguard Worker /// or a client channel (via \a ChannelArguments). 32*cc02d7e2SAndroid Build Coastguard Worker /// gRPC will attempt to keep memory and threads used by all attached entities 33*cc02d7e2SAndroid Build Coastguard Worker /// below the ResourceQuota bound. 34*cc02d7e2SAndroid Build Coastguard Worker class ResourceQuota final : private grpc::internal::GrpcLibrary { 35*cc02d7e2SAndroid Build Coastguard Worker public: 36*cc02d7e2SAndroid Build Coastguard Worker /// \param name - a unique name for this ResourceQuota. 37*cc02d7e2SAndroid Build Coastguard Worker explicit ResourceQuota(const std::string& name); 38*cc02d7e2SAndroid Build Coastguard Worker ResourceQuota(); 39*cc02d7e2SAndroid Build Coastguard Worker ~ResourceQuota() override; 40*cc02d7e2SAndroid Build Coastguard Worker 41*cc02d7e2SAndroid Build Coastguard Worker /// Resize this \a ResourceQuota to a new size. If \a new_size is smaller 42*cc02d7e2SAndroid Build Coastguard Worker /// than the current size of the pool, memory usage will be monotonically 43*cc02d7e2SAndroid Build Coastguard Worker /// decreased until it falls under \a new_size. 44*cc02d7e2SAndroid Build Coastguard Worker /// No time bound is given for this to occur however. 45*cc02d7e2SAndroid Build Coastguard Worker ResourceQuota& Resize(size_t new_size); 46*cc02d7e2SAndroid Build Coastguard Worker 47*cc02d7e2SAndroid Build Coastguard Worker /// Set the max number of threads that can be allocated from this 48*cc02d7e2SAndroid Build Coastguard Worker /// ResourceQuota object. 49*cc02d7e2SAndroid Build Coastguard Worker /// 50*cc02d7e2SAndroid Build Coastguard Worker /// If the new_max_threads value is smaller than the current value, no new 51*cc02d7e2SAndroid Build Coastguard Worker /// threads are allocated until the number of active threads fall below 52*cc02d7e2SAndroid Build Coastguard Worker /// new_max_threads. There is no time bound on when this may happen i.e none 53*cc02d7e2SAndroid Build Coastguard Worker /// of the current threads are forcefully destroyed and all threads run their 54*cc02d7e2SAndroid Build Coastguard Worker /// normal course. 55*cc02d7e2SAndroid Build Coastguard Worker ResourceQuota& SetMaxThreads(int new_max_threads); 56*cc02d7e2SAndroid Build Coastguard Worker c_resource_quota()57*cc02d7e2SAndroid Build Coastguard Worker grpc_resource_quota* c_resource_quota() const { return impl_; } 58*cc02d7e2SAndroid Build Coastguard Worker 59*cc02d7e2SAndroid Build Coastguard Worker private: 60*cc02d7e2SAndroid Build Coastguard Worker ResourceQuota(const ResourceQuota& rhs); 61*cc02d7e2SAndroid Build Coastguard Worker ResourceQuota& operator=(const ResourceQuota& rhs); 62*cc02d7e2SAndroid Build Coastguard Worker 63*cc02d7e2SAndroid Build Coastguard Worker grpc_resource_quota* const impl_; 64*cc02d7e2SAndroid Build Coastguard Worker }; 65*cc02d7e2SAndroid Build Coastguard Worker 66*cc02d7e2SAndroid Build Coastguard Worker } // namespace grpc 67*cc02d7e2SAndroid Build Coastguard Worker 68*cc02d7e2SAndroid Build Coastguard Worker #endif // GRPCPP_RESOURCE_QUOTA_H 69