| 778 | // Global thread pool |
| 779 | |
| 780 | static int ParseOMPEnvVar(const char* name) { |
| 781 | // OMP_NUM_THREADS is a comma-separated list of positive integers. |
| 782 | // We are only interested in the first (top-level) number. |
| 783 | auto result = GetEnvVar(name); |
| 784 | if (!result.ok()) { |
| 785 | return 0; |
| 786 | } |
| 787 | auto str = *std::move(result); |
| 788 | auto first_comma = str.find_first_of(','); |
| 789 | if (first_comma != std::string::npos) { |
| 790 | str = str.substr(0, first_comma); |
| 791 | } |
| 792 | try { |
| 793 | return std::max(0, std::stoi(str)); |
| 794 | } catch (...) { |
| 795 | return 0; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | int ThreadPool::DefaultCapacity() { |
| 800 | int capacity = ParseOMPEnvVar("OMP_NUM_THREADS"); |
no test coverage detected