| 381 | const int MAX_FD_SCAN_COUNT = 10003; |
| 382 | static butil::static_atomic<bool> s_ever_reached_fd_scan_limit = BUTIL_STATIC_ATOMIC_INIT(false); |
| 383 | class FdReader { |
| 384 | public: |
| 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 | |
| 406 | static int print_fd_count(void*) { |
| 407 | return CachedReader<int>::get_value(FdReader()); |