• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #if defined(_WIN32) || defined(__CYGWIN__)
2 	#include <windows.h>
3 #elif !defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__)
4 	#include <pthread.h>
5 #endif
6 
7 #include <cpuinfo.h>
8 #include <cpuinfo/internal-api.h>
9 #include <cpuinfo/log.h>
10 
11 #ifdef __APPLE__
12 	#include "TargetConditionals.h"
13 #endif
14 
15 
16 #if defined(_WIN32) || defined(__CYGWIN__)
17 	static INIT_ONCE init_guard = INIT_ONCE_STATIC_INIT;
18 #elif !defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__)
19 	static pthread_once_t init_guard = PTHREAD_ONCE_INIT;
20 #else
21 	static bool init_guard = false;
22 #endif
23 
cpuinfo_initialize(void)24 bool CPUINFO_ABI cpuinfo_initialize(void) {
25 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
26 	#if defined(__MACH__) && defined(__APPLE__)
27 		pthread_once(&init_guard, &cpuinfo_x86_mach_init);
28 	#elif defined(__linux__)
29 		pthread_once(&init_guard, &cpuinfo_x86_linux_init);
30 	#elif defined(_WIN32) || defined(__CYGWIN__)
31 		InitOnceExecuteOnce(&init_guard, &cpuinfo_x86_windows_init, NULL, NULL);
32 	#else
33 		cpuinfo_log_error("operating system is not supported in cpuinfo");
34 	#endif
35 #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
36 	#if defined(__linux__)
37 		pthread_once(&init_guard, &cpuinfo_arm_linux_init);
38 	#elif defined(__MACH__) && defined(__APPLE__)
39 		pthread_once(&init_guard, &cpuinfo_arm_mach_init);
40 	#else
41 		cpuinfo_log_error("operating system is not supported in cpuinfo");
42 	#endif
43 #elif CPUINFO_ARCH_ASMJS || CPUINFO_ARCH_WASM || CPUINFO_ARCH_WASMSIMD
44 	#if defined(__EMSCRIPTEN_PTHREADS__)
45 		pthread_once(&init_guard, &cpuinfo_emscripten_init);
46 	#else
47 		if (!init_guard) {
48 			cpuinfo_emscripten_init();
49 		}
50 		init_guard = true;
51 	#endif
52 #else
53 	cpuinfo_log_error("processor architecture is not supported in cpuinfo");
54 #endif
55 	return cpuinfo_is_initialized;
56 }
57 
cpuinfo_deinitialize(void)58 void CPUINFO_ABI cpuinfo_deinitialize(void) {
59 }
60