Skip to content

Commit

Permalink
Add FreeBSD-specific code bits for pthread_setaffinity_np support
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Dec 10, 2019
1 parent bd50af1 commit 043c3d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/OpenThreads/pthreads/CMakeLists.txt
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/OpenThreads/pthreads/PThread.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 043c3d8

Please sign in to comment.