MCPcopy Create free account
hub / github.com/apache/brpc / FdReader

Class FdReader

src/bvar/default_variables.cpp:383–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381const int MAX_FD_SCAN_COUNT = 10003;
382static butil::static_atomic<bool> s_ever_reached_fd_scan_limit = BUTIL_STATIC_ATOMIC_INIT(false);
383class FdReader {
384public:
385 bool operator()(int* stat) const {
386 if (s_ever_reached_fd_scan_limit.load(butil::memory_order_relaxed)) {
387 // Never update the count again.
388 return false;
389 }
390 const int count = get_fd_count(MAX_FD_SCAN_COUNT);
391 if (count < 0) {
392 return false;
393 }
394 if (count == MAX_FD_SCAN_COUNT - 2
395 && s_ever_reached_fd_scan_limit.exchange(
396 true, butil::memory_order_relaxed) == false) {
397 // Rename the bvar to notify user.
398 g_fd_num.hide();
399 g_fd_num.expose("process_fd_num_too_many");
400 }
401 *stat = count;
402 return true;
403 }
404};
405
406static int print_fd_count(void*) {
407 return CachedReader<int>::get_value(FdReader());

Callers 1

print_fd_countFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected