File tree 3 files changed +26
-1
lines changed
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ include(SwiftSupport)
24
24
include (GNUInstallDirs)
25
25
include (ExternalProject)
26
26
27
+ if (CMAKE_SYSTEM_NAME STREQUAL Linux)
28
+ include (CheckSymbolExists)
29
+ include (CheckIncludeFile)
30
+ list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
31
+ check_include_file("sched.h" HAVE_SCHED_H)
32
+ check_symbol_exists(sched_getaffinity "sched.h" HAVE_SCHED_GETAFFINITY)
33
+ endif ()
34
+
27
35
string (TOLOWER ${CMAKE_SYSTEM_NAME} swift_os)
28
36
get_swift_host_arch(swift_arch)
29
37
Original file line number Diff line number Diff line change 71
71
#include <pthread.h>
72
72
#endif
73
73
74
+ #if DEPLOYMENT_TARGET_LINUX
75
+ #ifdef HAVE_SCHED_GETAFFINITY
76
+ #include <sched.h>
77
+ #endif
78
+ #endif
74
79
75
80
76
81
#if !defined(CF_HAVE_HW_CONFIG_COMMPAGE ) && defined(_COMM_PAGE_LOGICAL_CPUS ) && defined(_COMM_PAGE_PHYSICAL_CPUS ) && defined(_COMM_PAGE_ACTIVE_CPUS ) && !__has_feature (address_sanitizer )
@@ -451,6 +456,14 @@ CF_PRIVATE CFIndex __CFActiveProcessorCount() {
451
456
pcnt = 0 ;
452
457
}
453
458
#elif DEPLOYMENT_TARGET_LINUX
459
+
460
+ #ifdef HAVE_SCHED_GETAFFINITY
461
+ cpu_set_t set ;
462
+ if (sched_getaffinity (getpid (), sizeof (set ), & set ) == 0 ) {
463
+ return CPU_COUNT (& set );
464
+ }
465
+ #endif
466
+
454
467
pcnt = sysconf (_SC_NPROCESSORS_ONLN );
455
468
#else
456
469
// Assume the worst
Original file line number Diff line number Diff line change @@ -337,6 +337,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android)
337
337
PRIVATE
338
338
-DDEPLOYMENT_TARGET_LINUX
339
339
-D_GNU_SOURCE)
340
+ if (HAVE_SCHED_GETAFFINITY)
341
+ target_compile_definitions (CoreFoundation
342
+ PRIVATE
343
+ -DHAVE_SCHED_GETAFFINITY)
344
+ endif ()
340
345
elseif (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
341
346
target_compile_definitions (CoreFoundation
342
347
PRIVATE
@@ -516,4 +521,3 @@ install(DIRECTORY
516
521
${CMAKE_INSTALL_PREFIX} /System /Library/Frameworks
517
522
USE_SOURCE_PERMISSIONS
518
523
PATTERN PrivateHeaders EXCLUDE )
519
-
You can’t perform that action at this time.
0 commit comments