Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 1 | #include <pthread.h> |
| 2 | |
| 3 | #include <cpuinfo.h> |
| 4 | #include <api.h> |
| 5 | |
Hao Lu | 922070c | 2017-10-18 16:29:02 -0700 | [diff] [blame] | 6 | #ifdef __APPLE__ |
| 7 | #include "TargetConditionals.h" |
| 8 | #endif |
| 9 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 10 | |
Marat Dukhan | 8ecad1a | 2017-05-08 07:21:57 +0000 | [diff] [blame] | 11 | struct cpuinfo_processor* cpuinfo_processors = NULL; |
Marat Dukhan | 43a51cd | 2017-09-22 16:35:05 -0700 | [diff] [blame] | 12 | struct cpuinfo_core* cpuinfo_cores = NULL; |
Marat Dukhan | 8ecad1a | 2017-05-08 07:21:57 +0000 | [diff] [blame] | 13 | struct cpuinfo_package* cpuinfo_packages = NULL; |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 14 | |
Marat Dukhan | 8ecad1a | 2017-05-08 07:21:57 +0000 | [diff] [blame] | 15 | uint32_t cpuinfo_processors_count = 0; |
| 16 | uint32_t cpuinfo_cores_count = 0; |
| 17 | uint32_t cpuinfo_packages_count = 0; |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 18 | |
| 19 | |
| 20 | static pthread_once_t init_guard = PTHREAD_ONCE_INIT; |
| 21 | |
| 22 | void CPUINFO_ABI cpuinfo_initialize(void) { |
| 23 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 24 | #if defined(__MACH__) && defined(__APPLE__) |
| 25 | pthread_once(&init_guard, &cpuinfo_x86_mach_init); |
| 26 | #elif defined(__linux__) |
| 27 | pthread_once(&init_guard, &cpuinfo_x86_linux_init); |
| 28 | #else |
| 29 | #error Unsupported target OS |
| 30 | #endif |
Marat Dukhan | ab42e7e | 2017-05-09 13:19:39 +0000 | [diff] [blame] | 31 | #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 32 | #if defined(__linux__) |
| 33 | pthread_once(&init_guard, &cpuinfo_arm_linux_init); |
Hao Lu | 922070c | 2017-10-18 16:29:02 -0700 | [diff] [blame] | 34 | #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
| 35 | pthread_once(&init_guard, &cpuinfo_arm_mach_init); |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 36 | #else |
| 37 | #error Unsupported target OS |
| 38 | #endif |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 39 | #else |
| 40 | #error Unsupported target architecture |
| 41 | #endif |
| 42 | } |
| 43 | |
| 44 | void CPUINFO_ABI cpuinfo_deinitialize(void) { |
| 45 | } |