Update tracy to 0.11.1

This commit is contained in:
2025-04-19 03:02:36 +03:00
parent af955ba418
commit 9645008460
22 changed files with 2004 additions and 282 deletions

View File

@@ -28,6 +28,9 @@
# include <sys/thr.h>
#elif defined __NetBSD__ || defined __DragonFly__
# include <sys/lwp.h>
#elif defined __QNX__
# include <process.h>
# include <sys/neutrino.h>
#endif
#ifdef __MINGW32__
@@ -82,6 +85,8 @@ TRACY_API uint32_t GetThreadHandleImpl()
return lwp_gettid();
#elif defined __OpenBSD__
return getthrid();
#elif defined __QNX__
return (uint32_t) gettid();
#elif defined __EMSCRIPTEN__
// Not supported, but let it compile.
return 0;
@@ -100,16 +105,10 @@ TRACY_API uint32_t GetThreadHandleImpl()
}
#ifdef TRACY_ENABLE
struct ThreadNameData
{
uint32_t id;
const char* name;
ThreadNameData* next;
};
std::atomic<ThreadNameData*>& GetThreadNameData();
#endif
#ifdef _MSC_VER
#if defined _MSC_VER && !defined __clang__
# pragma pack( push, 8 )
struct THREADNAME_INFO
{
@@ -133,6 +132,11 @@ void ThreadNameMsvcMagic( const THREADNAME_INFO& info )
#endif
TRACY_API void SetThreadName( const char* name )
{
SetThreadNameWithHint( name, 0 );
}
TRACY_API void SetThreadNameWithHint( const char* name, int32_t groupHint )
{
#if defined _WIN32
# ifdef TRACY_UWP
@@ -148,7 +152,7 @@ TRACY_API void SetThreadName( const char* name )
}
else
{
# if defined _MSC_VER
# if defined _MSC_VER && !defined __clang__
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name;
@@ -180,6 +184,21 @@ TRACY_API void SetThreadName( const char* name )
#endif
}
}
#elif defined __QNX__
{
const auto sz = strlen( name );
if( sz <= _NTO_THREAD_NAME_MAX )
{
pthread_setname_np( pthread_self(), name );
}
else
{
char buf[_NTO_THREAD_NAME_MAX + 1];
memcpy( buf, name, _NTO_THREAD_NAME_MAX );
buf[_NTO_THREAD_NAME_MAX] = '\0';
pthread_setname_np( pthread_self(), buf );
}
};
#endif
#ifdef TRACY_ENABLE
{
@@ -189,6 +208,7 @@ TRACY_API void SetThreadName( const char* name )
buf[sz] = '\0';
auto data = (ThreadNameData*)tracy_malloc_fast( sizeof( ThreadNameData ) );
data->id = detail::GetThreadHandleImpl();
data->groupHint = groupHint;
data->name = buf;
data->next = GetThreadNameData().load( std::memory_order_relaxed );
while( !GetThreadNameData().compare_exchange_weak( data->next, data, std::memory_order_release, std::memory_order_relaxed ) ) {}
@@ -196,6 +216,22 @@ TRACY_API void SetThreadName( const char* name )
#endif
}
#ifdef TRACY_ENABLE
ThreadNameData* GetThreadNameData( uint32_t id )
{
auto ptr = GetThreadNameData().load( std::memory_order_relaxed );
while( ptr )
{
if( ptr->id == id )
{
return ptr;
}
ptr = ptr->next;
}
return nullptr;
}
#endif
TRACY_API const char* GetThreadName( uint32_t id )
{
static char buf[256];
@@ -259,6 +295,11 @@ TRACY_API const char* GetThreadName( uint32_t id )
pthread_setcancelstate( cs, 0 );
# endif
return buf;
#elif defined __QNX__
static char qnxNameBuf[_NTO_THREAD_NAME_MAX + 1] = {0};
if (pthread_getname_np(static_cast<int>(id), qnxNameBuf, _NTO_THREAD_NAME_MAX) == 0) {
return qnxNameBuf;
};
#endif
sprintf( buf, "%" PRIu32, id );