Fixing crash on exit due to RP malloc not being deinitialized

This commit is contained in:
Andrey Voroshilov 2020-07-08 03:50:25 -07:00
parent 71ca0683d6
commit 199dc46e7d

View File

@ -929,6 +929,7 @@ TRACY_API void ShutdownProfiler()
{ {
delete s_profilerData; delete s_profilerData;
s_profilerData = nullptr; s_profilerData = nullptr;
rpmalloc_finalize();
} }
# else # else
static std::atomic<int> profilerDataLock { 0 }; static std::atomic<int> profilerDataLock { 0 };
@ -1033,6 +1034,7 @@ TRACY_API void ShutdownProfiler()
{ {
delete s_profiler; delete s_profiler;
s_profiler = nullptr; s_profiler = nullptr;
rpmalloc_finalize();
} }
TRACY_API Profiler& GetProfiler() { return *s_profiler; } TRACY_API Profiler& GetProfiler() { return *s_profiler; }
# else # else
@ -1213,12 +1215,25 @@ bool Profiler::ShouldExit()
return s_instance->m_shutdown.load( std::memory_order_relaxed ); return s_instance->m_shutdown.load( std::memory_order_relaxed );
} }
class ThreadExitHandler
{
public:
~ThreadExitHandler()
{
#ifdef TRACY_MANUAL_LIFETIME
rpmalloc_thread_finalize();
#endif
}
};
void Profiler::Worker() void Profiler::Worker()
{ {
#ifdef __linux__ #ifdef __linux__
s_profilerTid = syscall( SYS_gettid ); s_profilerTid = syscall( SYS_gettid );
#endif #endif
ThreadExitHandler threadExitHandler;
SetThreadName( "Tracy Profiler" ); SetThreadName( "Tracy Profiler" );
#ifdef TRACY_DATA_PORT #ifdef TRACY_DATA_PORT
@ -1639,6 +1654,8 @@ void Profiler::Worker()
void Profiler::CompressWorker() void Profiler::CompressWorker()
{ {
ThreadExitHandler threadExitHandler;
SetThreadName( "Tracy DXT1" ); SetThreadName( "Tracy DXT1" );
while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
rpmalloc_thread_initialize(); rpmalloc_thread_initialize();