| 2243 | } |
| 2244 | |
| 2245 | Result<int32_t> GetNumAffinityCores() { |
| 2246 | #if defined(__linux__) |
| 2247 | cpu_set_t mask; |
| 2248 | if (sched_getaffinity(0, sizeof(mask), &mask) == 0) { |
| 2249 | auto count = CPU_COUNT(&mask); |
| 2250 | if (count > 0 && |
| 2251 | static_cast<uint64_t>(count) < std::numeric_limits<uint32_t>::max()) { |
| 2252 | return static_cast<uint32_t>(count); |
| 2253 | } |
| 2254 | } |
| 2255 | return IOErrorFromErrno(errno, "Could not read the CPU affinity."); |
| 2256 | #else |
| 2257 | return Status::NotImplemented("Only implemented for Linux"); |
| 2258 | #endif |
| 2259 | } |
| 2260 | |
| 2261 | Result<void*> LoadDynamicLibrary(const char* path) { |
| 2262 | #ifdef _WIN32 |