Add FreeBSD-specific code bits for pthread_setaffinity_np support

This commit is contained in:
Dmitry Marakasov 2019-12-10 15:08:25 +03:00 committed by Robert Osfield
parent 56835cf821
commit 27e3f57da2
2 changed files with 14 additions and 0 deletions

View File

@ -80,8 +80,15 @@ ELSE()
# double check that pthread_setaffinity_np is available as FreeBSD header doesn't contain required function
CHECK_CXX_SOURCE_COMPILES("
#include <pthread.h>
#ifdef __FreeBSD__
#include <pthread_np.h>
#endif
int main() {
#ifdef __FreeBSD__
cpuset_t cpumask;
#else
cpu_set_t cpumask;
#endif
CPU_ZERO( &cpumask );
CPU_SET( 0, &cpumask );
pthread_setaffinity_np( pthread_self(), sizeof(cpumask), &cpumask);

View File

@ -21,6 +21,9 @@
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(__FreeBSD__)
#include <pthread_np.h>
#endif
#include <limits.h>
#if defined __linux__ || defined __sun || defined __APPLE__ || ANDROID
@ -113,7 +116,11 @@ namespace OpenThreads
static void setAffinity(const Affinity& affinity)
{
//std::cout<<"setProcessAffinity : "<< affinity.activeCPUs.size() <<std::endl;
#if defined(__FreeBSD__)
cpuset_t cpumask;
#else
cpu_set_t cpumask;
#endif
CPU_ZERO( &cpumask );
unsigned int numprocessors = OpenThreads::GetNumberOfProcessors();
if (affinity)