Skip to content

Commit 043c3d8

Browse files
committed
Add FreeBSD-specific code bits for pthread_setaffinity_np support
1 parent bd50af1 commit 043c3d8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/OpenThreads/pthreads/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,15 @@ ELSE()
8080
# double check that pthread_setaffinity_np is available as FreeBSD header doesn't contain required function
8181
CHECK_CXX_SOURCE_COMPILES("
8282
#include <pthread.h>
83+
#ifdef __FreeBSD__
84+
#include <pthread_np.h>
85+
#endif
8386
int main() {
87+
#ifdef __FreeBSD__
88+
cpuset_t cpumask;
89+
#else
8490
cpu_set_t cpumask;
91+
#endif
8592
CPU_ZERO( &cpumask );
8693
CPU_SET( 0, &cpumask );
8794
pthread_setaffinity_np( pthread_self(), sizeof(cpumask), &cpumask);

src/OpenThreads/pthreads/PThread.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include <sys/types.h>
2222
#include <unistd.h>
2323
#include <pthread.h>
24+
#if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(__FreeBSD__)
25+
#include <pthread_np.h>
26+
#endif
2427
#include <limits.h>
2528

2629
#if defined __linux__ || defined __sun || defined __APPLE__ || ANDROID
@@ -113,7 +116,11 @@ namespace OpenThreads
113116
static void setAffinity(const Affinity& affinity)
114117
{
115118
//std::cout<<"setProcessAffinity : "<< affinity.activeCPUs.size() <<std::endl;
119+
#if defined(__FreeBSD__)
120+
cpuset_t cpumask;
121+
#else
116122
cpu_set_t cpumask;
123+
#endif
117124
CPU_ZERO( &cpumask );
118125
unsigned int numprocessors = OpenThreads::GetNumberOfProcessors();
119126
if (affinity)

0 commit comments

Comments
 (0)