summaryrefslogtreecommitdiff
path: root/graphics/oidn/files/patch-common_thread.cpp
blob: 8237988992ca09fc7af650edb6df177dcd20d0a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--- common/thread.cpp.orig	2020-09-11 17:36:51 UTC
+++ common/thread.cpp
@@ -1,6 +1,8 @@
 // Copyright 2009-2020 Intel Corporation
 // SPDX-License-Identifier: Apache-2.0
 
+#include <pthread_np.h>
+
 #if defined(_MSC_VER)
   #pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
 #endif
@@ -120,7 +122,7 @@ namespace oidn {
       OIDN_WARNING("SetThreadGroupAffinity failed");
   }
 
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__FreeBSD__)
 
   // ---------------------------------------------------------------------------
   // ThreadAffinity: Linux
@@ -165,7 +167,7 @@ namespace oidn {
 
     for (size_t i = 0; i < threadIds.size(); ++i)
     {
-      cpu_set_t affinity;
+      cpuset_t affinity;
       CPU_ZERO(&affinity);
       CPU_SET(threadIds[i], &affinity);
 
@@ -182,7 +184,7 @@ namespace oidn {
     const pthread_t thread = pthread_self();
 
     // Save the current affinity
-    if (pthread_getaffinity_np(thread, sizeof(cpu_set_t), &oldAffinities[threadIndex]) != 0)
+    if (pthread_getaffinity_np(thread, sizeof(cpuset_t), &oldAffinities[threadIndex]) != 0)
     {
       OIDN_WARNING("pthread_getaffinity_np failed");
       oldAffinities[threadIndex] = affinities[threadIndex];
@@ -190,7 +192,7 @@ namespace oidn {
     }
 
     // Set the new affinity
-    if (pthread_setaffinity_np(thread, sizeof(cpu_set_t), &affinities[threadIndex]) != 0)
+    if (pthread_setaffinity_np(thread, sizeof(cpuset_t), &affinities[threadIndex]) != 0)
       OIDN_WARNING("pthread_setaffinity_np failed");
   }
 
@@ -202,7 +204,7 @@ namespace oidn {
     const pthread_t thread = pthread_self();
 
     // Restore the original affinity
-    if (pthread_setaffinity_np(thread, sizeof(cpu_set_t), &oldAffinities[threadIndex]) != 0)
+    if (pthread_setaffinity_np(thread, sizeof(cpuset_t), &oldAffinities[threadIndex]) != 0)
       OIDN_WARNING("pthread_setaffinity_np failed");
   }