Make sure SDL subsystems are initialized before starting threads
This commit is contained in:
1 parent
b378bc5c83
commit
b057159db7
3 files changed
+35
-20
No files matched your search
@@ -114,6 +114,7 @@ static SDL_bool SDL_MainIsReady = SDL_FALSE;
|
|||||||
#else
|
#else
|
||||||
static SDL_bool SDL_MainIsReady = SDL_TRUE;
|
static SDL_bool SDL_MainIsReady = SDL_TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
static SDL_bool SDL_main_thread_initialized = SDL_FALSE;
|
||||||
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
|
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
|
||||||
static Uint8 SDL_SubsystemRefCount[32];
|
static Uint8 SDL_SubsystemRefCount[32];
|
||||||
|
|
||||||
@@ -179,6 +180,36 @@ void SDL_SetMainReady(void)
|
|||||||
SDL_MainIsReady = SDL_TRUE;
|
SDL_MainIsReady = SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDL_InitMainThread(void)
|
||||||
|
{
|
||||||
|
if (SDL_main_thread_initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_InitTLSData();
|
||||||
|
#ifndef SDL_TIMERS_DISABLED
|
||||||
|
SDL_TicksInit();
|
||||||
|
#endif
|
||||||
|
SDL_LogInit();
|
||||||
|
|
||||||
|
SDL_main_thread_initialized = SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SDL_QuitMainThread(void)
|
||||||
|
{
|
||||||
|
if (!SDL_main_thread_initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_LogQuit();
|
||||||
|
#ifndef SDL_TIMERS_DISABLED
|
||||||
|
SDL_TicksQuit();
|
||||||
|
#endif
|
||||||
|
SDL_QuitTLSData();
|
||||||
|
|
||||||
|
SDL_main_thread_initialized = SDL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
int SDL_InitSubSystem(Uint32 flags)
|
int SDL_InitSubSystem(Uint32 flags)
|
||||||
{
|
{
|
||||||
Uint32 flags_initialized = 0;
|
Uint32 flags_initialized = 0;
|
||||||
@@ -187,9 +218,6 @@ int 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_InitTLSData();
|
|
||||||
SDL_LogInit();
|
|
||||||
|
|
||||||
/* Clear the error message */
|
/* Clear the error message */
|
||||||
SDL_ClearError();
|
SDL_ClearError();
|
||||||
|
|
||||||
@@ -205,10 +233,6 @@ int SDL_InitSubSystem(Uint32 flags)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SDL_TIMERS_DISABLED
|
|
||||||
SDL_TicksInit();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Initialize the event subsystem */
|
/* Initialize the event subsystem */
|
||||||
if (flags & SDL_INIT_EVENTS) {
|
if (flags & SDL_INIT_EVENTS) {
|
||||||
#ifndef SDL_EVENTS_DISABLED
|
#ifndef SDL_EVENTS_DISABLED
|
||||||
@@ -496,10 +520,6 @@ void SDL_Quit(void)
|
|||||||
#endif
|
#endif
|
||||||
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
|
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
|
||||||
|
|
||||||
#ifndef SDL_TIMERS_DISABLED
|
|
||||||
SDL_TicksQuit();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SDL_USE_LIBDBUS
|
#ifdef SDL_USE_LIBDBUS
|
||||||
SDL_DBus_Quit();
|
SDL_DBus_Quit();
|
||||||
#endif
|
#endif
|
||||||
@@ -507,14 +527,12 @@ void SDL_Quit(void)
|
|||||||
SDL_ClearHints();
|
SDL_ClearHints();
|
||||||
SDL_AssertionsQuit();
|
SDL_AssertionsQuit();
|
||||||
|
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
SDL_memset(SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount));
|
SDL_memset(SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount));
|
||||||
|
|
||||||
SDL_QuitTLSData();
|
SDL_QuitMainThread();
|
||||||
|
|
||||||
SDL_bInMainQuit = SDL_FALSE;
|
SDL_bInMainQuit = SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,6 +208,8 @@
|
|||||||
#include "SDL_assert.h"
|
#include "SDL_assert.h"
|
||||||
#include "SDL_log.h"
|
#include "SDL_log.h"
|
||||||
|
|
||||||
|
extern void SDL_InitMainThread(void);
|
||||||
|
|
||||||
#endif /* SDL_internal_h_ */
|
#endif /* SDL_internal_h_ */
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
#include "SDL_systhread.h"
|
#include "SDL_systhread.h"
|
||||||
#include "SDL_hints.h"
|
#include "SDL_hints.h"
|
||||||
#include "../SDL_error_c.h"
|
#include "../SDL_error_c.h"
|
||||||
#include "../timer/SDL_timer_c.h"
|
|
||||||
|
|
||||||
/* The storage is local to the thread, but the IDs are global for the process */
|
/* The storage is local to the thread, but the IDs are global for the process */
|
||||||
|
|
||||||
@@ -370,11 +369,7 @@ SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),
|
|||||||
SDL_Thread *thread;
|
SDL_Thread *thread;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
SDL_InitTLSData();
|
SDL_InitMainThread();
|
||||||
|
|
||||||
#ifndef SDL_TIMERS_DISABLED
|
|
||||||
SDL_TicksInit();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Allocate memory for the thread info structure */
|
/* Allocate memory for the thread info structure */
|
||||||
thread = (SDL_Thread *)SDL_calloc(1, sizeof(*thread));
|
thread = (SDL_Thread *)SDL_calloc(1, sizeof(*thread));
|
||||||
|
|||||||
Reference in new issue
Block a user