a51e54b4fd
* Fix cmake detection on pthread_affinity test on FreeBSD In FreeBSD, non posix thread functions locate in the pthread_np.h. We check the platform and include the correct header. Also, pthread related features in some platforms require link to special library. We append Threads target to BENCHMARK_CXX_LIBRARIES so that it can be added by cxx_feature_check. * fixup! Fix cmake detection on pthread_affinity test on FreeBSD --------- Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
20 lines
439 B
C++
20 lines
439 B
C++
#include <pthread.h>
|
|
#ifdef __FreeBSD__
|
|
#include <pthread_np.h>
|
|
#endif
|
|
int main() {
|
|
cpu_set_t set;
|
|
CPU_ZERO(&set);
|
|
for (int i = 0; i < CPU_SETSIZE; ++i) {
|
|
CPU_SET(i, &set);
|
|
CPU_CLR(i, &set);
|
|
}
|
|
pthread_t self = pthread_self();
|
|
int ret;
|
|
ret = pthread_getaffinity_np(self, sizeof(set), &set);
|
|
if (ret != 0) return ret;
|
|
ret = pthread_setaffinity_np(self, sizeof(set), &set);
|
|
if (ret != 0) return ret;
|
|
return 0;
|
|
}
|