mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-26 09:58:20 +01:00
protect logging with a mutex to prevent interleaving
I started logging from a thread and got problems
This commit is contained in:
parent
5a8d098597
commit
0d87cbc7d0
1 changed files with 4 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue