2017-09-10 15:46:20 +00:00
|
|
|
#ifndef __TRACYSYSTEM_HPP__
|
|
|
|
#define __TRACYSYSTEM_HPP__
|
|
|
|
|
2017-10-30 19:45:00 +00:00
|
|
|
#ifdef TRACY_ENABLE
|
2018-06-21 22:23:50 +00:00
|
|
|
# if defined __ANDROID__ || defined __CYGWIN__ || defined __APPLE__ || defined _GNU_SOURCE || ( defined _WIN32 && !defined NTDDI_WIN10_RS2 )
|
2017-10-30 19:45:00 +00:00
|
|
|
# define TRACY_COLLECT_THREAD_NAMES
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2017-09-25 22:46:46 +00:00
|
|
|
#ifdef _WIN32
|
2018-07-13 21:39:58 +00:00
|
|
|
#ifndef _WINDOWS_
|
2017-09-25 22:46:46 +00:00
|
|
|
extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(void);
|
2018-07-13 21:39:58 +00:00
|
|
|
#endif
|
2017-09-25 22:46:46 +00:00
|
|
|
#else
|
|
|
|
# include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
2017-09-25 19:13:59 +00:00
|
|
|
#include <stdint.h>
|
2017-09-10 15:46:20 +00:00
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
|
2017-09-25 22:46:46 +00:00
|
|
|
static inline uint64_t GetThreadHandle()
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
static_assert( sizeof( decltype( GetCurrentThreadId() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" );
|
|
|
|
return uint64_t( GetCurrentThreadId() );
|
2017-11-03 10:09:31 +00:00
|
|
|
#elif defined __APPLE__
|
2017-11-03 09:49:49 +00:00
|
|
|
uint64_t id;
|
2017-11-03 10:12:17 +00:00
|
|
|
pthread_threadid_np( pthread_self(), &id );
|
2017-11-03 09:49:49 +00:00
|
|
|
return id;
|
2017-09-25 22:46:46 +00:00
|
|
|
#else
|
|
|
|
static_assert( sizeof( decltype( pthread_self() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" );
|
|
|
|
return uint64_t( pthread_self() );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-09-10 15:46:20 +00:00
|
|
|
void SetThreadName( std::thread& thread, const char* name );
|
2017-10-16 19:01:57 +00:00
|
|
|
void SetThreadName( std::thread::native_handle_type handle, const char* name );
|
2017-09-25 19:13:59 +00:00
|
|
|
const char* GetThreadName( uint64_t id );
|
2017-09-10 15:46:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|