Updating Macros
Don't take away ability to do profiling on MacOS
This commit is contained in:
@@ -680,61 +680,49 @@ void CProfileManager::dumpAll()
|
|||||||
CProfileManager::Release_Iterator(profileIterator);
|
CProfileManager::Release_Iterator(profileIterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// BT_HAVE_TLS is defined to 1 when __thread should be supported.
|
// clang-format off
|
||||||
// We assume __thread is supported on Linux when compiled with Clang or compiled
|
#if defined(_WIN32) && (defined(__MINGW32__) || defined(__MINGW64__))
|
||||||
// against libstdc++ with _GLIBCXX_HAVE_TLS defined.
|
#define BT_HAVE_TLS 1
|
||||||
#ifdef BT_HAVE_TLS
|
#elif __APPLE__ && !TARGET_OS_IPHONE
|
||||||
#error BT_HAVE_TLS cannot be directly set
|
// TODO: Modern versions of iOS support TLS now with updated version checking.
|
||||||
#elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
|
#define BT_HAVE_TLS 1
|
||||||
#define BT_HAVE_TLS 1
|
#elif __linux__
|
||||||
|
#define BT_HAVE_TLS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// There are platforms for which TLS should not be used even though the compiler
|
// __thread is broken on Andorid clang until r12b. See
|
||||||
// makes it seem like it's supported (Android NDK < r12b for example).
|
// https://github.com/android-ndk/ndk/issues/8
|
||||||
// This is primarily because of linker problems and toolchain misconfiguration:
|
|
||||||
// TLS isn't supported until NDK r12b per
|
|
||||||
// https://developer.android.com/ndk/downloads/revision_history.html
|
|
||||||
// Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
|
|
||||||
// <android/ndk-version.h>. For NDK < r16, users should define these macros,
|
|
||||||
// e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11.
|
|
||||||
#if defined(__ANDROID__) && defined(__clang__)
|
#if defined(__ANDROID__) && defined(__clang__)
|
||||||
#if __has_include(<android/ndk-version.h>)
|
#if __has_include(<android/ndk-version.h>)
|
||||||
#include <android/ndk-version.h>
|
#include <android/ndk-version.h>
|
||||||
#endif // __has_include(<android/ndk-version.h>)
|
#endif // __has_include(<android/ndk-version.h>)
|
||||||
#if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
|
#if defined(__NDK_MAJOR__) && \
|
||||||
defined(__NDK_MINOR__) && \
|
|
||||||
((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
|
((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
|
||||||
#undef BT_HAVE_TLS
|
#undef BT_HAVE_TLS
|
||||||
#endif
|
#endif
|
||||||
#endif // defined(__ANDROID__) && defined(__clang__)
|
#endif // defined(__ANDROID__) && defined(__clang__)
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
unsigned int btQuickprofGetCurrentThreadIndex2()
|
unsigned int btQuickprofGetCurrentThreadIndex2() {
|
||||||
{
|
|
||||||
#if BT_THREADSAFE
|
|
||||||
return btGetCurrentThreadIndex();
|
|
||||||
#else
|
|
||||||
const unsigned int kNullIndex = ~0U;
|
const unsigned int kNullIndex = ~0U;
|
||||||
#ifdef _WIN32
|
|
||||||
#if defined(__MINGW32__) || defined(__MINGW64__)
|
#if BT_THREADSAFE
|
||||||
static __thread unsigned int sThreadIndex = kNullIndex;
|
return btGetCurrentThreadIndex();
|
||||||
#else
|
|
||||||
__declspec(thread) static unsigned int sThreadIndex = kNullIndex;
|
|
||||||
#endif
|
|
||||||
#elif defined(BT_HAVE_TLS)
|
#elif defined(BT_HAVE_TLS)
|
||||||
static __thread unsigned int sThreadIndex = kNullIndex;
|
static __thread unsigned int sThreadIndex = kNullIndex;
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
__declspec(thread) static unsigned int sThreadIndex = kNullIndex;
|
||||||
#else
|
#else
|
||||||
unsigned int sThreadIndex = 0;
|
unsigned int sThreadIndex = 0;
|
||||||
return -1;
|
return -1;
|
||||||
#endif //_WIN32
|
#endif
|
||||||
|
|
||||||
// TODO: Use std::atomic? Not sure if c++11 is a prereq for this library.
|
|
||||||
static int gThreadCounter = 0;
|
static int gThreadCounter = 0;
|
||||||
|
|
||||||
if (sThreadIndex == kNullIndex) {
|
if (sThreadIndex == kNullIndex) {
|
||||||
sThreadIndex = gThreadCounter++;
|
sThreadIndex = gThreadCounter++;
|
||||||
}
|
}
|
||||||
return sThreadIndex;
|
return sThreadIndex;
|
||||||
#endif // #else // #if BT_THREADSAFE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void btEnterProfileZoneDefault(const char* name)
|
void btEnterProfileZoneDefault(const char* name)
|
||||||
|
|||||||
Reference in New Issue
Block a user