mirror of https://github.com/encounter/SDL.git
log: Wrap the call to the logging implementation in a mutex.
Fixes #2463.
This commit is contained in:
parent
2a42952281
commit
c4141bc11c
|
@ -147,6 +147,9 @@ SDL_SetMainReady(void)
|
||||||
SDL_MainIsReady = SDL_TRUE;
|
SDL_MainIsReady = SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDL_LogInit(void);
|
||||||
|
void SDL_LogQuit(void);
|
||||||
|
|
||||||
int
|
int
|
||||||
SDL_InitSubSystem(Uint32 flags)
|
SDL_InitSubSystem(Uint32 flags)
|
||||||
{
|
{
|
||||||
|
@ -156,6 +159,8 @@ SDL_InitSubSystem(Uint32 flags)
|
||||||
return SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
|
return SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_LogInit();
|
||||||
|
|
||||||
/* Clear the error message */
|
/* Clear the error message */
|
||||||
SDL_ClearError();
|
SDL_ClearError();
|
||||||
|
|
||||||
|
@ -470,12 +475,13 @@ SDL_Quit(void)
|
||||||
|
|
||||||
SDL_ClearHints();
|
SDL_ClearHints();
|
||||||
SDL_AssertionsQuit();
|
SDL_AssertionsQuit();
|
||||||
SDL_LogResetPriorities();
|
|
||||||
|
|
||||||
#if SDL_USE_LIBDBUS
|
#if SDL_USE_LIBDBUS
|
||||||
SDL_DBus_Quit();
|
SDL_DBus_Quit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SDL_LogQuit();
|
||||||
|
|
||||||
/* Now that every subsystem has been quit, we reset the subsystem refcount
|
/* Now that every subsystem has been quit, we reset the subsystem refcount
|
||||||
* and the list of initialized subsystems.
|
* and the list of initialized subsystems.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "SDL_error.h"
|
#include "SDL_error.h"
|
||||||
#include "SDL_log.h"
|
#include "SDL_log.h"
|
||||||
|
#include "SDL_mutex.h"
|
||||||
|
|
||||||
#if HAVE_STDIO_H
|
#if HAVE_STDIO_H
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -59,6 +60,7 @@ static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
|
||||||
static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY;
|
static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY;
|
||||||
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
|
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
|
||||||
static void *SDL_log_userdata = NULL;
|
static void *SDL_log_userdata = NULL;
|
||||||
|
static SDL_mutex *log_function_mutex = NULL;
|
||||||
|
|
||||||
static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
|
static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -92,6 +94,24 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
|
||||||
};
|
};
|
||||||
#endif /* __ANDROID__ */
|
#endif /* __ANDROID__ */
|
||||||
|
|
||||||
|
void
|
||||||
|
SDL_LogInit(void)
|
||||||
|
{
|
||||||
|
if (!log_function_mutex) {
|
||||||
|
/* if this fails we'll try to continue without it. */
|
||||||
|
log_function_mutex = SDL_CreateMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SDL_LogQuit(void)
|
||||||
|
{
|
||||||
|
SDL_LogResetPriorities();
|
||||||
|
if (log_function_mutex) {
|
||||||
|
SDL_DestroyMutex(log_function_mutex);
|
||||||
|
log_function_mutex = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SDL_LogSetAllPriority(SDL_LogPriority priority)
|
SDL_LogSetAllPriority(SDL_LogPriority priority)
|
||||||
|
@ -298,7 +318,12 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first! */
|
||||||
|
if (!log_function_mutex) { log_function_mutex = SDL_CreateMutex(); }
|
||||||
|
if (log_function_mutex) { SDL_LockMutex(log_function_mutex); }
|
||||||
SDL_log_function(SDL_log_userdata, category, priority, message);
|
SDL_log_function(SDL_log_userdata, category, priority, message);
|
||||||
|
if (log_function_mutex) { SDL_UnlockMutex(log_function_mutex); }
|
||||||
|
|
||||||
SDL_free(message);
|
SDL_free(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue