Line and braces tweaks

This commit is contained in:
Joshua Kriegshauser 2024-09-30 20:22:13 -07:00
parent 97a6a3dde7
commit 9dfb1e98b9

View File

@ -1473,8 +1473,7 @@ Profiler::Profiler()
m_pipeBufSize = 16384; m_pipeBufSize = 16384;
# else # else
m_pipeBufSize = (int)(ptrdiff_t)m_safeSendBufferSize; m_pipeBufSize = (int)(ptrdiff_t)m_safeSendBufferSize;
while( fcntl( m_pipe[0], F_SETPIPE_SZ, m_pipeBufSize ) < 0 && errno == EPERM ) while( fcntl( m_pipe[0], F_SETPIPE_SZ, m_pipeBufSize ) < 0 && errno == EPERM ) m_pipeBufSize /= 2; // too big; reduce
m_pipeBufSize /= 2; // too big; reduce
m_pipeBufSize = fcntl( m_pipe[0], F_GETPIPE_SZ ); m_pipeBufSize = fcntl( m_pipe[0], F_GETPIPE_SZ );
# endif # endif
fcntl( m_pipe[1], F_SETFL, O_NONBLOCK ); fcntl( m_pipe[1], F_SETFL, O_NONBLOCK );
@ -1522,19 +1521,17 @@ void Profiler::RemoveCrashHandler()
if( m_crashHandlerInstalled ) if( m_crashHandlerInstalled )
{ {
auto prev = SetUnhandledExceptionFilter( (LPTOP_LEVEL_EXCEPTION_FILTER)m_prevHandler ); auto prev = SetUnhandledExceptionFilter( (LPTOP_LEVEL_EXCEPTION_FILTER)m_prevHandler );
if( prev != CrashFilter ) if( prev != CrashFilter ) SetUnhandledExceptionFilter( prev ); // A different exception filter was installed over ours => put it back
SetUnhandledExceptionFilter( prev ); // A different exception filter was installed over ours => put it back
} }
#endif #endif
#if defined __linux__ && !defined TRACY_NO_CRASH_HANDLER #if defined __linux__ && !defined TRACY_NO_CRASH_HANDLER
if( m_crashHandlerInstalled ) if( m_crashHandlerInstalled )
{ {
auto restore = [this]( int signum, struct sigaction* prev ) { auto restore = [ this ]( int signum, struct sigaction* prev ) {
struct sigaction old; struct sigaction old;
sigaction( signum, prev, &old ); sigaction( signum, prev, &old );
if( old.sa_sigaction != CrashHandler ) if( old.sa_sigaction != CrashHandler ) sigaction( signum, &old, nullptr ); // A different signal handler was installed over ours => put it back
sigaction( signum, &old, nullptr ); // A different signal handler was installed over ours => put it back
}; };
restore( TRACY_CRASH_SIGNAL, &m_prevSignal.pwr ); restore( TRACY_CRASH_SIGNAL, &m_prevSignal.pwr );
restore( SIGILL, &m_prevSignal.ill ); restore( SIGILL, &m_prevSignal.ill );
@ -3108,10 +3105,7 @@ char* Profiler::SafeCopyProlog( const char* data, size_t size )
assert( !m_inUse.exchange(true) ); assert( !m_inUse.exchange(true) );
#endif #endif
if( size > m_safeSendBufferSize ) if( size > m_safeSendBufferSize ) buf = (char*)tracy_malloc( size );
{
buf = (char*)tracy_malloc( size );
}
#ifdef _WIN32 #ifdef _WIN32
__try __try
@ -3128,15 +3122,13 @@ char* Profiler::SafeCopyProlog( const char* data, size_t size )
{ {
size_t sendsize = size - offset; size_t sendsize = size - offset;
ssize_t result1, result2; ssize_t result1, result2;
while( ( result1 = write( m_pipe[1], data + offset, sendsize ) ) < 0 && errno == EINTR ) while( ( result1 = write( m_pipe[1], data + offset, sendsize ) ) < 0 && errno == EINTR ) { /* retry */ }
/* retry */;
if( result1 < 0 ) if( result1 < 0 )
{ {
success = false; success = false;
break; break;
} }
while( ( result2 = read( m_pipe[0], buf + offset, result1 ) ) < 0 && errno == EINTR ) while( ( result2 = read( m_pipe[0], buf + offset, result1 ) ) < 0 && errno == EINTR ) { /* retry */ }
/* retry */;
if( result2 != result1 ) if( result2 != result1 )
{ {
success = false; success = false;
@ -3146,8 +3138,7 @@ char* Profiler::SafeCopyProlog( const char* data, size_t size )
} }
#endif #endif
if( success ) if( success ) return buf;
return buf;
SafeCopyEpilog( buf ); SafeCopyEpilog( buf );
return nullptr; return nullptr;
@ -3155,8 +3146,7 @@ char* Profiler::SafeCopyProlog( const char* data, size_t size )
void Profiler::SafeCopyEpilog( char* buf ) void Profiler::SafeCopyEpilog( char* buf )
{ {
if( buf != m_safeSendBuffer ) if( buf != m_safeSendBuffer ) tracy_free( buf );
tracy_free( buf );
#ifndef NDEBUG #ifndef NDEBUG
m_inUse.store( false ); m_inUse.store( false );
@ -4117,13 +4107,12 @@ void Profiler::HandleSymbolCodeQuery( uint64_t symbol, uint32_t size )
} }
else else
{ {
// 'symbol' may have come from a module that has since unloaded, perform a safe copy before sending auto&& lambda = [ this, symbol ]( const char* buf, size_t size ) {
if( WithSafeCopy( (const char*)symbol, size, [this, symbol]( const char* buf, size_t size ) {
SendLongString( symbol, buf, size, QueueType::SymbolCode ); SendLongString( symbol, buf, size, QueueType::SymbolCode );
})) };
return;
AckSymbolCodeNotAvailable(); // 'symbol' may have come from a module that has since unloaded, perform a safe copy before sending
if( !WithSafeCopy( (const char*)symbol, size, lambda ) ) AckSymbolCodeNotAvailable();
} }
} }