// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #include #include #include #if ANKI_POSIX # include # include #elif ANKI_OS_WINDOWS # include #else # error "Unimplemented" #endif // For print backtrace #if ANKI_POSIX && !ANKI_OS_ANDROID # include # include #endif namespace anki { U32 getCpuCoresCount() { #if ANKI_POSIX return U32(sysconf(_SC_NPROCESSORS_ONLN)); #elif ANKI_OS_WINDOWS SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); return sysinfo.dwNumberOfProcessors; #else # error "Unimplemented" #endif } void getBacktrace(BackTraceWalker& walker) { #if ANKI_POSIX && !ANKI_OS_ANDROID // Get addresses's for all entries on the stack const U32 maxStackSize = 64; void** array = static_cast(malloc(maxStackSize * sizeof(void*))); if(array) { const I32 size = backtrace(array, I32(maxStackSize)); // Get symbols char** strings = backtrace_symbols(array, size); if(strings) { for(I32 i = 0; i < size; ++i) { walker(strings[i]); } free(strings); } free(array); } #else walker("getBacktrace() not supported in " ANKI_OS_STR); #endif } Bool runningFromATerminal() { #if ANKI_POSIX return isatty(fileno(stdin)); #else return false; #endif } } // end namespace anki