YEP
authorhgn <hgodden00@gmail.com>
Sat, 31 May 2025 18:03:14 +0000 (19:03 +0100)
committerhgn <hgodden00@gmail.com>
Sat, 31 May 2025 18:03:14 +0000 (19:03 +0100)
vg_log.c
vg_log.h

index 59698c73b989f8d00c0c3022dcdf89315fc61bf4..bb8183046bc163b229341737de17038681181d04 100644 (file)
--- a/vg_log.c
+++ b/vg_log.c
@@ -5,8 +5,10 @@
 #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;
@@ -26,16 +28,18 @@ static void _vg_log_append_line( const char *str )
 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
 }
 
@@ -50,11 +54,13 @@ void _vg_logx_va( FILE *file, const char *location, const char *prefix,
       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];
@@ -88,13 +94,15 @@ void _vg_logx_va( FILE *file, const char *location, const char *prefix,
       {
          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
          }
 
@@ -107,11 +115,13 @@ void _vg_logx_va( FILE *file, const char *location, const char *prefix,
       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
 }
 
index 9084fe846fb337c56a80268472e615ba49546f5d..f768f8fdea802e0c15cb15328a17cd9664f537b2 100644 (file)
--- a/vg_log.h
+++ b/vg_log.h
  #include "dep/sdl/include/SDL.h"
 #endif
 
+#ifdef VG_ENGINE
+ #define VG_MULTITHREAD
+#endif
+
 struct vg_log
 {
    char log[64][96];
    u32  log_line_count, log_line_current;
 
    bool initialized;
-#ifdef VG_ENGINE
+#ifdef VG_MULTITHREAD
+ #ifdef VG_ENGINE
    SDL_mutex *mutex;
-#else
+ #else
    pthread_mutex_t lock;
+ #endif
 #endif
 }
 extern vg_log;