| 77 | |
| 78 | |
| 79 | static void set_thread_affinity(std::thread& thread, int index) { |
| 80 | #if !defined(__linux__) || defined(_OPENMP) |
| 81 | (void)thread; |
| 82 | (void)index; |
| 83 | throw std::runtime_error("Setting thread affinity is only supported in Linux binaries built " |
| 84 | "with -DOPENMP_RUNTIME=NONE"); |
| 85 | #else |
| 86 | cpu_set_t cpuset; |
| 87 | CPU_ZERO(&cpuset); |
| 88 | CPU_SET(index, &cpuset); |
| 89 | const int status = pthread_setaffinity_np(thread.native_handle(), sizeof (cpu_set_t), &cpuset); |
| 90 | if (status != 0) { |
| 91 | throw std::runtime_error("Error calling pthread_setaffinity_np: " |
| 92 | + std::to_string(status)); |
| 93 | } |
| 94 | #endif |
| 95 | } |
| 96 | |
| 97 | static thread_local Worker* local_worker = nullptr; |
| 98 | |