SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::InitState Struct Reference

A structure used for thread-safe initialization and shutdown. More...

Inheritance diagram for SDL::InitState:
Inheritance graph
[legend]
Collaboration diagram for SDL::InitState:
Collaboration graph
[legend]

Public Member Functions

bool ShouldInit ()
 Return whether initialization should be done. More...
 
bool ShouldQuit ()
 Return whether cleanup should be done. More...
 
void SetInitialized (bool initialized)
 Finish an initialization state transition. More...
 

Detailed Description

Here is an example of using this:

static SDL::InitState init;
bool InitSystem(void)
{
if (!InitState.ShouldInit(&init)) {
// The system is initialized
return true;
}
// At this point, you should not leave this function without calling
bool initialized = DoInitTasks();
InitState.SetInitialized(&init, initialized);
return initialized;
}
bool UseSubsystem(void)
{
if (InitState.ShouldInit(&init)) {
// Error, the subsystem isn't initialized
InitState.SetInitialized(&init, false);
return false;
}
// Do work using the initialized subsystem
return true;
}
void QuitSystem(void)
{
if (!InitState.ShouldQuit(&init)) {
// The system is not initialized
return;
}
// At this point, you should not leave this function without calling
InitState.SetInitialized()
DoQuitTasks();
InitState.SetInitialized(&init, false);
}
bool ShouldInit()
Return whether initialization should be done.
Definition: SDL3pp_mutex.h:1953
void SetInitialized(bool initialized)
Finish an initialization state transition.
Definition: SDL3pp_mutex.h:2000
A structure used for thread-safe initialization and shutdown.
Definition: SDL3pp_mutex.h:1863

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.2.0.

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