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 2121#include <dispatch/dispatch.h>
2222#include <stdio.h>
2323#if defined(__unix__ ) || (defined(__APPLE__ ) && defined(__MACH__ ))
24+ #include <pthread.h>
2425#include <unistd.h>
2526#ifdef __ANDROID__
2627#include <linux/sysctl.h>
@@ -83,6 +84,14 @@ static void test_apply_contended(dispatch_queue_t dq)
8384 uint32_t activecpu ;
8485#if defined(__linux__ ) || defined(__OpenBSD__ ) || defined(__FreeBSD__ )
8586 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
8695#elif defined(_WIN32 )
8796 SYSTEM_INFO si ;
8897 GetSystemInfo (& si );
Original file line number Diff line number Diff line change 11#include <bsdtests.h>
22#include "dispatch_test.h"
33
4+ #if defined(__linux__ )
5+ // For pthread_getaffinity_np()
6+ #include <pthread.h>
7+ #endif
8+
49struct test_context {
510 uint32_t ncpu ;
611 int flag ;
@@ -35,6 +40,15 @@ activecpu(void)
3540 uint32_t activecpu ;
3641#if defined(__linux__ ) || defined(__OpenBSD__ )
3742 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+
3852#elif defined(_WIN32 )
3953 SYSTEM_INFO si ;
4054 GetSystemInfo (& si );
You can’t perform that action at this time.
0 commit comments