SDL_InitState(3type)
π«Ά SDL_InitState π«Ά
okay bestie, welcome to the SDL3 DATATYPES corner of the manual, where we're talking about SDL_InitState β the little struct that lets you do thread-safe initialization and shutdown. yes queen, concurrency, we love her π
β¨ NAME β¨
SDL_InitState β a structure used for thread-safe initialization and shutdown. that's it, that's the whole vibe π¦
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_mutex.h>
typedef struct SDL_InitState
{
SDL_AtomicInt status;
SDL_ThreadID thread;
void *reserved;
} SDL_InitState;
look at her. three fields. status, thread, reserved. don't touch reserved babe, that one's not for you π
π DESCRIPTION π
here's an example of using this, and honestly? it's giving textbook β¨
static SDL_InitState 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;
}
// At this point, you should not leave this function without calling SDL_SetInitialized()
DoQuitTasks();
SDL_SetInitialized(&init, false);
}
so like, read the comments fr fr β you should not leave this function without calling SDL_SetInitialized(). that part is in the source comments twice, so it's not a suggestion, it's the rules bestie π
β οΈ okay important, no cap: this doesn't protect any resources created during initialization, and it doesn't 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. the struct handles the init/shutdown handshake, not your whole life π
π AVAILABILITY π
this struct is available since SDL 3.2.0. she's new-ish, she's fresh, she ate π
and that's the whole page, bestie π«Ά this was SDL_InitState(3type), from the Simple Directmedia Layer era of SDL 3.4.18 β go forth and initialize things thread-safely, mwah πβ¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms