File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 21
21
#include <dispatch/dispatch.h>
22
22
#include <stdio.h>
23
23
#if defined(__unix__ ) || (defined(__APPLE__ ) && defined(__MACH__ ))
24
+ #include <pthread.h>
24
25
#include <unistd.h>
25
26
#ifdef __ANDROID__
26
27
#include <linux/sysctl.h>
@@ -83,6 +84,14 @@ static void test_apply_contended(dispatch_queue_t dq)
83
84
uint32_t activecpu ;
84
85
#if defined(__linux__ ) || defined(__OpenBSD__ ) || defined(__FreeBSD__ )
85
86
activecpu = (uint32_t )sysconf (_SC_NPROCESSORS_ONLN );
87
+
88
+ #if defined(__linux__ ) && __USE_GNU
89
+ cpu_set_t cpuset ;
90
+ if (pthread_getaffinity_np (pthread_self (),
91
+ sizeof (cpu_set_t ),
92
+ & cpuset ) == 0 )
93
+ activecpu = (uint32_t )CPU_COUNT (& cpuset );
94
+ #endif
86
95
#elif defined(_WIN32 )
87
96
SYSTEM_INFO si ;
88
97
GetSystemInfo (& si );
Original file line number Diff line number Diff line change 1
1
#include <bsdtests.h>
2
2
#include "dispatch_test.h"
3
3
4
+ #if defined(__linux__ )
5
+ // For pthread_getaffinity_np()
6
+ #include <pthread.h>
7
+ #endif
8
+
4
9
struct test_context {
5
10
uint32_t ncpu ;
6
11
int flag ;
@@ -35,6 +40,15 @@ activecpu(void)
35
40
uint32_t activecpu ;
36
41
#if defined(__linux__ ) || defined(__OpenBSD__ )
37
42
activecpu = (uint32_t )sysconf (_SC_NPROCESSORS_ONLN );
43
+
44
+ #if defined(__linux__ ) && __USE_GNU
45
+ cpu_set_t cpuset ;
46
+ if (pthread_getaffinity_np (pthread_self (),
47
+ sizeof (cpu_set_t ),
48
+ & cpuset ) == 0 )
49
+ activecpu = (uint32_t )CPU_COUNT (& cpuset );
50
+ #endif
51
+
38
52
#elif defined(_WIN32 )
39
53
SYSTEM_INFO si ;
40
54
GetSystemInfo (& si );
You can’t perform that action at this time.
0 commit comments