From: hgn Date: Sat, 31 May 2025 18:03:14 +0000 (+0100) Subject: YEP X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=37936a4eb395f41608e065edfaae2361d78ca392;p=vg.git YEP --- diff --git a/vg_log.c b/vg_log.c index 59698c7..bb81830 100644 --- a/vg_log.c +++ b/vg_log.c @@ -5,8 +5,10 @@ #include "vg_log.h" #include "vg_string.h" -#ifndef VG_ENGINE -#include +#ifdef VG_MULTITHREAD + #ifndef VG_ENGINE + #include + #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 } diff --git a/vg_log.h b/vg_log.h index 9084fe8..f768f8f 100644 --- a/vg_log.h +++ b/vg_log.h @@ -43,16 +43,22 @@ #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;