/Users/deen/code/yugabyte-db/src/yb/util/ulimit.cc
Line | Count | Source |
1 | | // Portions Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | |
13 | | #include "yb/util/ulimit.h" |
14 | | |
15 | | #include <sys/resource.h> |
16 | | |
17 | | namespace yb { |
18 | | |
19 | 475k | ResourceLimit::ResourceLimit(int64_t value) : value_(value) {} |
20 | | |
21 | 144k | std::string ResourceLimit::ToString() const { |
22 | 144k | if (IsUnlimited()) return "unlimited"; |
23 | 51.6k | return std::to_string(value_); |
24 | 51.6k | } |
25 | | |
26 | 82.6k | bool ResourceLimit::IsNegative() const { |
27 | 82.6k | return !IsUnlimited() && value_ < 0; |
28 | 82.6k | } |
29 | | |
30 | 587k | bool ResourceLimit::IsUnlimited() const { |
31 | 587k | return value_ == static_cast<int64_t>(RLIM_INFINITY); |
32 | 587k | } |
33 | | |
34 | 20.6k | bool ResourceLimit::operator==(const ResourceLimit& other) const { |
35 | 20.6k | return value_ == other.value_; |
36 | 20.6k | } |
37 | | |
38 | 113k | bool ResourceLimit::operator<(const ResourceLimit& other) const { |
39 | 113k | if (IsUnlimited()) return false; |
40 | 60.8k | if (other.IsUnlimited()) return true; |
41 | 59.8k | return value_ < other.value_; |
42 | 59.8k | } |
43 | | |
44 | 82.6k | bool ResourceLimit::operator<=(const ResourceLimit& other) const { |
45 | 82.6k | return !(other < *this); |
46 | 82.6k | } |
47 | | |
48 | 81.5k | int64_t ResourceLimit::RawValue() const { |
49 | 81.5k | return value_; |
50 | 81.5k | } |
51 | | |
52 | | } // namespace yb |