protect logging with a mutex to prevent interleaving

I started logging from a thread and got problems
This commit is contained in:
Eric House 2024-01-24 10:02:41 -08:00
parent 5a8d098597
commit 0d87cbc7d0

View file

@ -39,9 +39,12 @@
#ifdef DEBUG
static pthread_mutex_t sLogMutex = PTHREAD_MUTEX_INITIALIZER;
static void
debugf( const char* format, va_list ap )
{
pthread_mutex_lock( &sLogMutex );
struct timespec tp = {0};
int res = clock_gettime( CLOCK_REALTIME, &tp );
XP_ASSERT( 0 == res );
@ -53,6 +56,7 @@ debugf( const char* format, va_list ap )
vfprintf( stderr, format, ap );
fprintf( stderr, "%c", '\n' );
pthread_mutex_unlock( &sLogMutex );
}
void