2017-09-10 15:46:20 +00:00
|
|
|
#ifndef __TRACYSYSTEM_HPP__
|
|
|
|
#define __TRACYSYSTEM_HPP__
|
|
|
|
|
2019-08-14 00:22:45 +00:00
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
2019-02-19 18:36:30 +00:00
|
|
|
# ifndef _WINDOWS_
|
2017-09-25 22:46:46 +00:00
|
|
|
extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(void);
|
2019-02-19 18:36:30 +00:00
|
|
|
# endif
|
2019-11-05 19:09:40 +00:00
|
|
|
#elif defined __APPLE__ || ( !defined __ANDROID__ && !defined __linux__ )
|
2017-09-25 22:46:46 +00:00
|
|
|
# include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
2019-08-19 13:09:47 +00:00
|
|
|
#ifdef __linux__
|
2019-08-13 23:57:10 +00:00
|
|
|
# include <unistd.h>
|
2019-08-19 13:09:47 +00:00
|
|
|
# ifdef __ANDROID__
|
|
|
|
# include <sys/types.h>
|
|
|
|
# else
|
|
|
|
# include <sys/syscall.h>
|
|
|
|
# endif
|
2019-08-13 23:57:10 +00:00
|
|
|
#endif
|
|
|
|
|
2017-09-25 19:13:59 +00:00
|
|
|
#include <stdint.h>
|
2017-09-10 15:46:20 +00:00
|
|
|
|
2019-06-07 13:56:46 +00:00
|
|
|
#include "TracyApi.h"
|
|
|
|
|
2017-09-10 15:46:20 +00:00
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
|
2019-06-25 13:44:49 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
2019-06-24 17:19:47 +00:00
|
|
|
static inline uint64_t GetThreadHandleImpl()
|
2017-09-25 22:46:46 +00:00
|
|
|
{
|
2019-08-14 00:22:45 +00:00
|
|
|
#if defined _WIN32 || defined __CYGWIN__
|
2017-09-25 22:46:46 +00:00
|
|
|
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;
|
2019-08-13 23:57:10 +00:00
|
|
|
#elif defined __ANDROID__
|
|
|
|
return (uint64_t)gettid();
|
|
|
|
#elif defined __linux__
|
|
|
|
return (uint64_t)syscall( SYS_gettid );
|
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
|
|
|
|
}
|
2019-06-25 13:44:49 +00:00
|
|
|
}
|
2017-09-25 22:46:46 +00:00
|
|
|
|
2019-06-25 13:44:49 +00:00
|
|
|
#ifdef TRACY_ENABLE
|
2019-06-26 17:32:52 +00:00
|
|
|
TRACY_API uint64_t GetThreadHandle();
|
2019-06-25 13:44:49 +00:00
|
|
|
#else
|
|
|
|
static inline uint64_t GetThreadHandle()
|
|
|
|
{
|
|
|
|
return detail::GetThreadHandleImpl();
|
|
|
|
}
|
2019-06-24 17:18:52 +00:00
|
|
|
#endif
|
|
|
|
|
2019-08-14 00:22:45 +00:00
|
|
|
void SetThreadName( 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
|