#include "vg_log.h"
#include "vg_string.h"
-#ifndef VG_ENGINE
-#include <pthread.h>
+#ifdef VG_MULTITHREAD
+ #ifndef VG_ENGINE
+ #include <pthread.h>
+ #endif
#endif
struct vg_log vg_log;
void vg_log_init(void)
{
vg_log.initialized = 1;
-#ifdef VG_ENGINE
+#ifdef VG_MULTITHREAD
+ #ifdef VG_ENGINE
vg_log.mutex = SDL_CreateMutex();
if( vg_log.mutex == NULL )
{
printf( "SDL2 Error: %s\n", SDL_GetError() );
exit(-1);
}
-#else
+ #else
if( pthread_mutex_init( &vg_log.lock, NULL ) )
exit(-1);
+ #endif
#endif
}
return;
}
-#ifdef VG_ENGINE
+#ifdef VG_MULTITHREAD
+ #ifdef VG_ENGINE
if( SDL_LockMutex( vg_log.mutex ) )
vg_fatal_error( "" );
-#else
+ #else
pthread_mutex_lock( &vg_log.lock );
+ #endif
#endif
char buffer[4096], line[96];
{
if( location )
{
-#ifdef VG_ENGINE
+#ifdef VG_MULTITHREAD
+ #ifdef VG_ENGINE
const char *thread_colours[] = { KGRN, KMAG, KCYN, KYEL, KBLU };
const char *colour = thread_colours[(vg_thread_purpose() % VG_ARRAY_LEN( thread_colours ))];
fprintf( file, "%s%u|"KNRM"%.32s", colour, vg_thread_purpose(), location );
-#else
+ #else
fprintf( file, KNRM "%.32s", location );
+ #endif
#endif
}
if( buffer[i+1] == '\0' ) break;
}
-#ifdef VG_ENGINE
+#ifdef VG_MULTITHREAD
+ #ifdef VG_ENGINE
if( SDL_UnlockMutex( vg_log.mutex ) )
vg_fatal_error( "" );
-#else
+ #else
pthread_mutex_unlock( &vg_log.lock );
+ #endif
#endif
}