SDL 3.0
SDL_InitState Struct Reference

#include <SDL_mutex.h>

+ Collaboration diagram for SDL_InitState:

Data Fields

SDL_AtomicInt status
 
SDL_ThreadID thread
 
void * reserved
 

Detailed Description

A structure used for thread-safe initialization and shutdown.

Here is an example of using this:

static SDL_AtomicInitState init;
bool InitSystem(void)
{
if (!SDL_ShouldInit(&init)) {
// The system is initialized
return true;
}
// At this point, you should not leave this function without calling SDL_SetInitialized()
bool initialized = DoInitTasks();
SDL_SetInitialized(&init, initialized);
return initialized;
}
bool UseSubsystem(void)
{
if (SDL_ShouldInit(&init)) {
// Error, the subsystem isn't initialized
SDL_SetInitialized(&init, false);
return false;
}
// Do work using the initialized subsystem
return true;
}
void QuitSystem(void)
{
if (!SDL_ShouldQuit(&init)) {
// The system is not initialized
return true;
}
// At this point, you should not leave this function without calling SDL_SetInitialized()
DoQuitTasks();
SDL_SetInitialized(&init, false);
}
bool SDL_ShouldInit(SDL_InitState *state)
void SDL_SetInitialized(SDL_InitState *state, bool initialized)
bool SDL_ShouldQuit(SDL_InitState *state)

Note that this doesn't protect any resources created during initialization, or guarantee that nobody is using those resources during cleanup. You should use other mechanisms to protect those, if that's a concern for your code.

Since
This struct is available since SDL 3.1.3.

Definition at line 836 of file SDL_mutex.h.

Field Documentation

◆ reserved

void* SDL_InitState::reserved

Definition at line 840 of file SDL_mutex.h.

◆ status

SDL_AtomicInt SDL_InitState::status

Definition at line 838 of file SDL_mutex.h.

◆ thread

SDL_ThreadID SDL_InitState::thread

Definition at line 839 of file SDL_mutex.h.


The documentation for this struct was generated from the following file: