Urho3D/Source/ThirdParty/Tracy/client/TracyThread.hpp
SuperWangKai 30a629ca21
Tracy profiler integration. (#2776)
* Tracy profiler integration.

* Cleanup URHO3D_TRACY_PROFILING macro.

* Fix comment of Tracy build option.

* Decouple URHO3D_TRACY_PROFILING exclusively from URHO3D_PROFILING.

* Comment explains URHO3D_TRACY_PROFILING

* Update

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update

* Update TracyCallstack.cpp

* Update

* Update CMakeLists.txt

* Update TracyCallstack.cpp

* Update TracyCallstack.cpp

Co-authored-by: 1vanK <1vanK@users.noreply.github.com>
2021-02-16 17:56:04 +03:00

86 lines
1.5 KiB
C++

#ifndef __TRACYTHREAD_HPP__
#define __TRACYTHREAD_HPP__
#if defined _WIN32 || defined __CYGWIN__
# include <windows.h>
#else
# include <pthread.h>
#endif
#ifdef TRACY_MANUAL_LIFETIME
# include "tracy_rpmalloc.hpp"
#endif
namespace tracy
{
class ThreadExitHandler
{
public:
~ThreadExitHandler()
{
#ifdef TRACY_MANUAL_LIFETIME
rpmalloc_thread_finalize();
#endif
}
};
#if defined _WIN32 || defined __CYGWIN__
class Thread
{
public:
Thread( void(*func)( void* ptr ), void* ptr )
: m_func( func )
, m_ptr( ptr )
, m_hnd( CreateThread( nullptr, 0, Launch, this, 0, nullptr ) )
{}
~Thread()
{
WaitForSingleObject( m_hnd, INFINITE );
CloseHandle( m_hnd );
}
HANDLE Handle() const { return m_hnd; }
private:
static DWORD WINAPI Launch( void* ptr ) { ((Thread*)ptr)->m_func( ((Thread*)ptr)->m_ptr ); return 0; }
void(*m_func)( void* ptr );
void* m_ptr;
HANDLE m_hnd;
};
#else
class Thread
{
public:
Thread( void(*func)( void* ptr ), void* ptr )
: m_func( func )
, m_ptr( ptr )
{
pthread_create( &m_thread, nullptr, Launch, this );
}
~Thread()
{
pthread_join( m_thread, nullptr );
}
pthread_t Handle() const { return m_thread; }
private:
static void* Launch( void* ptr ) { ((Thread*)ptr)->m_func( ((Thread*)ptr)->m_ptr ); return nullptr; }
void(*m_func)( void* ptr );
void* m_ptr;
pthread_t m_thread;
};
#endif
}
#endif