mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 10:41:50 +00:00
Merge TracyThread.hpp to TracySystem.cpp.
Keeping threading functions inside a source file prevents poisoning by including windows.h.
This commit is contained in:
parent
0d24a2739d
commit
206305fbd2
@ -21,7 +21,6 @@
|
|||||||
#include "concurrentqueue.h"
|
#include "concurrentqueue.h"
|
||||||
#include "TracyScoped.hpp"
|
#include "TracyScoped.hpp"
|
||||||
#include "TracyProfiler.hpp"
|
#include "TracyProfiler.hpp"
|
||||||
#include "TracyThread.hpp"
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
# define DISABLE_LZ4
|
# define DISABLE_LZ4
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "../common/TracySystem.hpp"
|
||||||
#include "TracyProfiler.hpp"
|
#include "TracyProfiler.hpp"
|
||||||
#include "TracyThread.hpp"
|
|
||||||
|
|
||||||
namespace tracy
|
namespace tracy
|
||||||
{
|
{
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
#ifndef __TRACYTHREAD_HPP__
|
|
||||||
#define __TRACYTHREAD_HPP__
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <pthread.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace tracy
|
|
||||||
{
|
|
||||||
|
|
||||||
static inline uint64_t GetThreadHandle()
|
|
||||||
{
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
static_assert( sizeof( decltype( GetCurrentThreadId() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" );
|
|
||||||
return uint64_t( GetCurrentThreadId() );
|
|
||||||
#else
|
|
||||||
static_assert( sizeof( decltype( pthread_self() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" );
|
|
||||||
return uint64_t( pthread_self() );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline const char* GetThreadName( uint64_t id )
|
|
||||||
{
|
|
||||||
static char buf[256];
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
# ifdef NTDDI_WIN10_RS2
|
|
||||||
auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, id );
|
|
||||||
PWSTR tmp;
|
|
||||||
GetThreadDescription( hnd, &tmp );
|
|
||||||
auto ret = wcstombs( buf, tmp, 256 );
|
|
||||||
CloseHandle( hnd );
|
|
||||||
if( ret != 0 )
|
|
||||||
{
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
if( pthread_getname_np( (pthread_t)id, buf, 256 ) == 0 )
|
|
||||||
{
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
sprintf( buf, "%" PRIu64, id );
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -6,12 +6,24 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "TracySystem.hpp"
|
#include "TracySystem.hpp"
|
||||||
|
|
||||||
namespace tracy
|
namespace tracy
|
||||||
{
|
{
|
||||||
|
|
||||||
|
uint64_t GetThreadHandle()
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
static_assert( sizeof( decltype( GetCurrentThreadId() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" );
|
||||||
|
return uint64_t( GetCurrentThreadId() );
|
||||||
|
#else
|
||||||
|
static_assert( sizeof( decltype( pthread_self() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" );
|
||||||
|
return uint64_t( pthread_self() );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void SetThreadName( std::thread& thread, const char* name )
|
void SetThreadName( std::thread& thread, const char* name )
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -62,4 +74,29 @@ void SetThreadName( std::thread& thread, const char* name )
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* GetThreadName( uint64_t id )
|
||||||
|
{
|
||||||
|
static char buf[256];
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# ifdef NTDDI_WIN10_RS2
|
||||||
|
auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, (DWORD)id );
|
||||||
|
PWSTR tmp;
|
||||||
|
GetThreadDescription( hnd, &tmp );
|
||||||
|
auto ret = wcstombs( buf, tmp, 256 );
|
||||||
|
CloseHandle( hnd );
|
||||||
|
if( ret != 0 )
|
||||||
|
{
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
if( pthread_getname_np( (pthread_t)id, buf, 256 ) == 0 )
|
||||||
|
{
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
sprintf( buf, "%" PRIu64, id );
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
#ifndef __TRACYSYSTEM_HPP__
|
#ifndef __TRACYSYSTEM_HPP__
|
||||||
#define __TRACYSYSTEM_HPP__
|
#define __TRACYSYSTEM_HPP__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
namespace tracy
|
namespace tracy
|
||||||
{
|
{
|
||||||
|
|
||||||
|
uint64_t GetThreadHandle();
|
||||||
void SetThreadName( std::thread& thread, const char* name );
|
void SetThreadName( std::thread& thread, const char* name );
|
||||||
|
const char* GetThreadName( uint64_t id );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user