xref: /third_party/benchmark/cmake/pthread_affinity.cpp
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/benchmark/cmake/
1a8c51b3fSopenharmony_ci#include <pthread.h>
2a8c51b3fSopenharmony_ciint main() {
3a8c51b3fSopenharmony_ci  cpu_set_t set;
4a8c51b3fSopenharmony_ci  CPU_ZERO(&set);
5a8c51b3fSopenharmony_ci  for (int i = 0; i < CPU_SETSIZE; ++i) {
6a8c51b3fSopenharmony_ci    CPU_SET(i, &set);
7a8c51b3fSopenharmony_ci    CPU_CLR(i, &set);
8a8c51b3fSopenharmony_ci  }
9a8c51b3fSopenharmony_ci  pthread_t self = pthread_self();
10a8c51b3fSopenharmony_ci  int ret;
11a8c51b3fSopenharmony_ci  ret = pthread_getaffinity_np(self, sizeof(set), &set);
12a8c51b3fSopenharmony_ci  if (ret != 0) return ret;
13a8c51b3fSopenharmony_ci  ret = pthread_setaffinity_np(self, sizeof(set), &set);
14a8c51b3fSopenharmony_ci  if (ret != 0) return ret;
15a8c51b3fSopenharmony_ci  return 0;
16a8c51b3fSopenharmony_ci}
17

Indexes created Thu Nov 07 10:32:03 CST 2024