SDL.c File Reference
`#include "./SDL_internal.h"`
`#include "SDL.h"`
`#include "SDL_bits.h"`
`#include "SDL_revision.h"`
`#include "SDL_assert_c.h"`
`#include "events/SDL_events_c.h"`
`#include "haptic/SDL_haptic_c.h"`
`#include "joystick/SDL_joystick_c.h"`
Include dependency graph for SDL.c:

Go to the source code of this file.

## Functions

int | SDL_TimerInit (void)
void | SDL_TimerQuit (void)
void | SDL_TicksInit (void)
void | SDL_TicksQuit (void)
static void | SDL_PrivateSubsystemRefCountIncr (Uint32 subsystem)
static void | SDL_PrivateSubsystemRefCountDecr (Uint32 subsystem)
static SDL_bool | SDL_PrivateShouldInitSubsystem (Uint32 subsystem)
static SDL_bool | SDL_PrivateShouldQuitSubsystem (Uint32 subsystem)
void | SDL_SetMainReady (void)
int | SDL_InitSubSystem (Uint32 flags)
int | SDL_Init (Uint32 flags)
void | SDL_QuitSubSystem (Uint32 flags)
Uint32 | SDL_WasInit (Uint32 flags)
void | SDL_Quit (void)
void | SDL_GetVersion (SDL_version *ver)
| Get the version of SDL that is linked against your program. More...
const char * | SDL_GetRevision (void)
| Get the code revision of SDL that is linked against your program. More...
int | SDL_GetRevisionNumber (void)
| Get the revision number of SDL that is linked against your program. More...
const char * | SDL_GetPlatform ()
| Gets the name of the platform. More...

## Variables

static SDL_bool | SDL_MainIsReady = SDL_TRUE
static SDL_bool | SDL_bInMainQuit = SDL_FALSE
static Uint8 | SDL_SubsystemRefCount [32]

## Function Documentation

const char* SDL_GetPlatform | ( | void |  | ) |

Gets the name of the platform.

Definition at line 398 of file SDL.c.

References APIENTRY, and TRUE.

{
#if __AIX__
return "AIX";
#elif __ANDROID__
return "Android";
#elif __BSDI__
return "BSDI";
#elif __DREAMCAST__
return "Dreamcast";
#elif __EMSCRIPTEN__
return "Emscripten";
#elif __FREEBSD__
return "FreeBSD";
#elif __HAIKU__
return "Haiku";
#elif __HPUX__
return "HP-UX";
#elif __IRIX__
return "Irix";
#elif __LINUX__
return "Linux";
#elif __MINT__
return "Atari MiNT";
#elif __MACOS__
return "MacOS Classic";
#elif __MACOSX__
return "Mac OS X";
#elif __NACL__
return "NaCl";
#elif __NETBSD__
return "NetBSD";
#elif __OPENBSD__
return "OpenBSD";
#elif __OS2__
return "OS/2";
#elif __OSF__
return "OSF/1";
#elif __QNXNTO__
return "QNX Neutrino";
#elif __RISCOS__
return "RISC OS";
#elif __SOLARIS__
return "Solaris";
#elif __WIN32__
return "Windows";
#elif __WINRT__
return "WinRT";
#elif __IPHONEOS__
return "iOS";
#elif __PSP__
return "PlayStation Portable";
#else
return "Unknown (see SDL_platform.h)";
#endif
}

const char* SDL_GetRevision | ( | void |  | ) |

Get the code revision of SDL that is linked against your program.

Returns an arbitrary string (a hash value) uniquely identifying the exact revision of the SDL library in use, and is only useful in comparing against other revisions. It is NOT an incrementing number.

Definition at line 384 of file SDL.c.

References SDL_REVISION.

{
return SDL_REVISION;
}
SDL_REVISION
#define SDL_REVISION
Definition: SDL_revision.h:1

int SDL_GetRevisionNumber | ( | void |  | ) |

Get the revision number of SDL that is linked against your program.

Returns a number uniquely identifying the exact revision of the SDL library in use. It is an incrementing number based on commits to hg.libsdl.org.

Definition at line 391 of file SDL.c.

References SDL_REVISION_NUMBER.

{
return SDL_REVISION_NUMBER;
}
SDL_REVISION_NUMBER
#define SDL_REVISION_NUMBER
Definition: SDL_revision.h:2

void SDL_GetVersion | ( | SDL_version * | ver | ) |

Get the version of SDL that is linked against your program.

If you are linking to SDL dynamically, then it is possible that the current version will be different than the version you compiled against. This function returns the current version, while SDL_VERSION() is a macro that tells you what version you compiled with.

SDL_version compiled;
SDL_version linked;
SDL_VERSION(&compiled);
SDL_GetVersion(&linked);
printf("We compiled against SDL version %d.%d.%d ...\n",
compiled.major, compiled.minor, compiled.patch);
printf("But we linked against SDL version %d.%d.%d.\n",
linked.major, linked.minor, linked.patch);

This function may be called safely at any time, even before SDL_Init().

See also
  SDL_VERSION

Definition at line 377 of file SDL.c.

References SDL_VERSION.

{
SDL_VERSION(ver);
}
SDL_VERSION
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
Definition: SDL_version.h:79

int SDL_Init | ( | Uint32 | flags | ) |

This function initializes the subsystems specified by `flags`

Definition at line 242 of file SDL.c.

References SDL_InitSubSystem().

{
return SDL_InitSubSystem(flags);
}
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_InitSubSystem
int SDL_InitSubSystem(Uint32 flags)
Definition: SDL.c:108

int SDL_InitSubSystem | ( | Uint32 | flags | ) |

This function initializes specific SDL subsystems

Subsystem initialization is ref-counted, you must call SDL_QuitSubSystem for each SDL_InitSubSystem to correctly shutdown a subsystem manually (or call SDL_Quit to force shutdown). If a subsystem is already loaded then this call will increase the ref-count and return.

Definition at line 108 of file SDL.c.

References NULL, SDL_AudioInit, SDL_ClearError, SDL_GameControllerInit(), SDL_HapticInit(), SDL_INIT_AUDIO, SDL_INIT_EVENTS, SDL_INIT_GAMECONTROLLER, SDL_INIT_HAPTIC, SDL_INIT_JOYSTICK, SDL_INIT_TIMER, SDL_INIT_VIDEO, SDL_JoystickInit(), SDL_MainIsReady, SDL_PrivateShouldInitSubsystem(), SDL_PrivateSubsystemRefCountIncr(), SDL_QuitInit(), SDL_SetError, SDL_StartEventLoop(), SDL_TicksInit(), SDL_TimerInit(), and SDL_VideoInit.

Referenced by SDL_Init().

{
if (!SDL_MainIsReady) {
SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
return -1;
}
/* Clear the error message */
SDL_ClearError();
#if SDL_VIDEO_DRIVER_WINDOWS
if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
if (SDL_HelperWindowCreate() < 0) {
return -1;
}
}
#endif
#if !SDL_TIMERS_DISABLED
SDL_TicksInit();
#endif
if ((flags & SDL_INIT_GAMECONTROLLER)) {
/* game controller implies joystick */
flags |= SDL_INIT_JOYSTICK;
}
if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) {
/* video or joystick implies events */
flags |= SDL_INIT_EVENTS;
}
/* Initialize the event subsystem */
if ((flags & SDL_INIT_EVENTS)) {
#if !SDL_EVENTS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
if (SDL_StartEventLoop() < 0) {
return (-1);
}
SDL_QuitInit();
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
#else
return SDL_SetError("SDL not built with events support");
#endif
}
/* Initialize the timer subsystem */
if ((flags & SDL_INIT_TIMER)){
#if !SDL_TIMERS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
#else
return SDL_SetError("SDL not built with timer support");
#endif
}
/* Initialize the video subsystem */
if ((flags & SDL_INIT_VIDEO)){
#if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL) < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
#else
return SDL_SetError("SDL not built with video support");
#endif
}
/* Initialize the audio subsystem */
if ((flags & SDL_INIT_AUDIO)){
#if !SDL_AUDIO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
if (SDL_AudioInit(NULL) < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
#else
return SDL_SetError("SDL not built with audio support");
#endif
}
/* Initialize the joystick subsystem */
if ((flags & SDL_INIT_JOYSTICK)){
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
#else
return SDL_SetError("SDL not built with joystick support");
#endif
}
if ((flags & SDL_INIT_GAMECONTROLLER)){
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
if (SDL_GameControllerInit() < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
#else
return SDL_SetError("SDL not built with joystick support");
#endif
}
/* Initialize the haptic subsystem */
if ((flags & SDL_INIT_HAPTIC)){
#if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
#else
return SDL_SetError("SDL not built with haptic (force feedback) support");
#endif
}
return (0);
}
SDL_ClearError
#define SDL_ClearError
Definition: SDL_dynapi_overrides.h:120
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:81
SDL_MainIsReady
static SDL_bool SDL_MainIsReady
Definition: SDL.c:54
SDL_INIT_JOYSTICK
#define SDL_INIT_JOYSTICK
Definition: SDL.h:78
SDL_AudioInit
#define SDL_AudioInit
Definition: SDL_dynapi_overrides.h:81
SDL_JoystickInit
int SDL_JoystickInit(void)
Definition: SDL_joystick.c:50
SDL_StartEventLoop
int SDL_StartEventLoop(void)
Definition: SDL_events.c:160
SDL_QuitInit
int SDL_QuitInit(void)
Definition: SDL_quit.c:92
SDL_PrivateSubsystemRefCountIncr
static void SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
Definition: SDL.c:61
SDL_VideoInit
#define SDL_VideoInit
Definition: SDL_dynapi_overrides.h:502
NULL
#define NULL
Definition: begin_code.h:143
SDL_PrivateShouldInitSubsystem
static SDL_bool SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
Definition: SDL.c:80
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
SDL_INIT_TIMER
#define SDL_INIT_TIMER
Definition: SDL.h:75
SDL_INIT_AUDIO
#define SDL_INIT_AUDIO
Definition: SDL.h:76
SDL_TicksInit
void SDL_TicksInit(void)
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_INIT_GAMECONTROLLER
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:80
SDL_INIT_HAPTIC
#define SDL_INIT_HAPTIC
Definition: SDL.h:79
SDL_GameControllerInit
int SDL_GameControllerInit(void)
Definition: SDL_gamecontroller.c:860
SDL_HapticInit
int SDL_HapticInit(void)
Definition: SDL_haptic.c:35
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:77
SDL_TimerInit
int SDL_TimerInit(void)
Definition: SDL_timer.c:206

static SDL_bool SDL_PrivateShouldInitSubsystem | ( | Uint32 | subsystem | ) |

static

Definition at line 80 of file SDL.c.

References SDL_assert, SDL_MostSignificantBitIndex32(), and SDL_SubsystemRefCount.

Referenced by SDL_InitSubSystem().

{
int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
return (SDL_SubsystemRefCount[subsystem_index] == 0);
}
SDL_SubsystemRefCount
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
SDL_MostSignificantBitIndex32
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:51
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:167

static SDL_bool SDL_PrivateShouldQuitSubsystem | ( | Uint32 | subsystem | ) |

static

Definition at line 89 of file SDL.c.

References SDL_bInMainQuit, SDL_FALSE, SDL_MostSignificantBitIndex32(), and SDL_SubsystemRefCount.

Referenced by SDL_QuitSubSystem().

{
int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
if (SDL_SubsystemRefCount[subsystem_index] == 0) {
return SDL_FALSE;
}
/* If we're in SDL_Quit, we shut down every subsystem, even if refcount
* isn't zero.
*/
return SDL_SubsystemRefCount[subsystem_index] == 1 || SDL_bInMainQuit;
}
SDL_SubsystemRefCount
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
SDL_MostSignificantBitIndex32
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:51
SDL_bInMainQuit
static SDL_bool SDL_bInMainQuit
Definition: SDL.c:56
SDL_FALSE
Definition: SDL_stdinc.h:128

static void SDL_PrivateSubsystemRefCountDecr | ( | Uint32 | subsystem | ) |

static

Definition at line 70 of file SDL.c.

References SDL_MostSignificantBitIndex32(), and SDL_SubsystemRefCount.

Referenced by SDL_QuitSubSystem().

{
int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
if (SDL_SubsystemRefCount[subsystem_index] > 0) {
--SDL_SubsystemRefCount[subsystem_index];
}
}
SDL_SubsystemRefCount
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
SDL_MostSignificantBitIndex32
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:51

static void SDL_PrivateSubsystemRefCountIncr | ( | Uint32 | subsystem | ) |

static

Definition at line 61 of file SDL.c.

References SDL_assert, SDL_MostSignificantBitIndex32(), and SDL_SubsystemRefCount.

Referenced by SDL_InitSubSystem().

{
int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
++SDL_SubsystemRefCount[subsystem_index];
}
SDL_SubsystemRefCount
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
SDL_MostSignificantBitIndex32
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:51
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:167

void SDL_Quit | ( | void |  | ) |

This function cleans up all initialized subsystems. You should call it upon all exit conditions.

Definition at line 349 of file SDL.c.

References SDL_AssertionsQuit(), SDL_bInMainQuit, SDL_ClearHints, SDL_FALSE, SDL_INIT_EVERYTHING, SDL_LogResetPriorities, SDL_memset, SDL_QuitSubSystem(), SDL_SubsystemRefCount, SDL_TicksQuit(), and SDL_TRUE.

{
SDL_bInMainQuit = SDL_TRUE;
/* Quit all subsystems */
#if SDL_VIDEO_DRIVER_WINDOWS
SDL_HelperWindowDestroy();
#endif
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
#if !SDL_TIMERS_DISABLED
SDL_TicksQuit();
#endif
SDL_ClearHints();
SDL_AssertionsQuit();
SDL_LogResetPriorities();
/* Now that every subsystem has been quit, we reset the subsystem refcount
* and the list of initialized subsystems.
*/
SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) );
SDL_bInMainQuit = SDL_FALSE;
}
SDL_LogResetPriorities
#define SDL_LogResetPriorities
Definition: SDL_dynapi_overrides.h:244
SDL_SubsystemRefCount
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
SDL_QuitSubSystem
void SDL_QuitSubSystem(Uint32 flags)
Definition: SDL.c:248
SDL_ClearHints
#define SDL_ClearHints
Definition: SDL_dynapi_overrides.h:200
SDL_bInMainQuit
static SDL_bool SDL_bInMainQuit
Definition: SDL.c:56
SDL_TicksQuit
void SDL_TicksQuit(void)
SDL_AssertionsQuit
void SDL_AssertionsQuit(void)
Definition: SDL_assert.c:332
SDL_INIT_EVERYTHING
#define SDL_INIT_EVERYTHING
Definition: SDL.h:83
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128
x0
GLuint GLfloat x0
Definition: SDL_opengl_glext.h:8583
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:392

void SDL_QuitSubSystem | ( | Uint32 | flags | ) |

This function cleans up specific SDL subsystems

Definition at line 248 of file SDL.c.

References SDL_AudioQuit, SDL_GameControllerQuit(), SDL_HapticQuit(), SDL_INIT_AUDIO, SDL_INIT_EVENTS, SDL_INIT_GAMECONTROLLER, SDL_INIT_HAPTIC, SDL_INIT_JOYSTICK, SDL_INIT_TIMER, SDL_INIT_VIDEO, SDL_JoystickQuit(), SDL_PrivateShouldQuitSubsystem(), SDL_PrivateSubsystemRefCountDecr(), SDL_QuitQuit(), SDL_StopEventLoop(), SDL_TimerQuit(), and SDL_VideoQuit.

Referenced by SDL_Quit().

{
/* Shut down requested initialized subsystems */
#if !SDL_JOYSTICK_DISABLED
if ((flags & SDL_INIT_GAMECONTROLLER)) {
/* game controller implies joystick */
flags |= SDL_INIT_JOYSTICK;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
SDL_GameControllerQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
}
if ((flags & SDL_INIT_JOYSTICK)) {
/* joystick implies events */
flags |= SDL_INIT_EVENTS;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
SDL_JoystickQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
}
#endif
#if !SDL_HAPTIC_DISABLED
if ((flags & SDL_INIT_HAPTIC)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
SDL_HapticQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
}
#endif
#if !SDL_AUDIO_DISABLED
if ((flags & SDL_INIT_AUDIO)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
SDL_AudioQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
}
#endif
#if !SDL_VIDEO_DISABLED
if ((flags & SDL_INIT_VIDEO)) {
/* video implies events */
flags |= SDL_INIT_EVENTS;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
SDL_VideoQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
}
#endif
#if !SDL_TIMERS_DISABLED
if ((flags & SDL_INIT_TIMER)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
SDL_TimerQuit();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
}
#endif
#if !SDL_EVENTS_DISABLED
if ((flags & SDL_INIT_EVENTS)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
SDL_QuitQuit();
SDL_StopEventLoop();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
}
#endif
}
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:81
SDL_HapticQuit
void SDL_HapticQuit(void)
Definition: SDL_haptic.c:389
SDL_INIT_JOYSTICK
#define SDL_INIT_JOYSTICK
Definition: SDL.h:78
SDL_TimerQuit
void SDL_TimerQuit(void)
Definition: SDL_timer.c:246
SDL_AudioQuit
#define SDL_AudioQuit
Definition: SDL_dynapi_overrides.h:82
SDL_GameControllerQuit
void SDL_GameControllerQuit(void)
Definition: SDL_gamecontroller.c:1200
SDL_INIT_TIMER
#define SDL_INIT_TIMER
Definition: SDL.h:75
SDL_INIT_AUDIO
#define SDL_INIT_AUDIO
Definition: SDL.h:76
SDL_PrivateSubsystemRefCountDecr
static void SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
Definition: SDL.c:70
SDL_VideoQuit
#define SDL_VideoQuit
Definition: SDL_dynapi_overrides.h:503
SDL_PrivateShouldQuitSubsystem
static SDL_bool SDL_PrivateShouldQuitSubsystem(Uint32 subsystem)
Definition: SDL.c:89
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
SDL_INIT_GAMECONTROLLER
#define SDL_INIT_GAMECONTROLLER
Definition: SDL.h:80
SDL_JoystickQuit
void SDL_JoystickQuit(void)
Definition: SDL_joystick.c:458
SDL_INIT_HAPTIC
#define SDL_INIT_HAPTIC
Definition: SDL.h:79
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:77
SDL_QuitQuit
void SDL_QuitQuit(void)
Definition: SDL_quit.c:130
SDL_StopEventLoop
void SDL_StopEventLoop(void)
Definition: SDL_events.c:90

void SDL_SetMainReady | ( | void |  | ) |

This is called by the real SDL main function to let the rest of the library know that initialization was done properly.

Calling this yourself without knowing what you're doing can cause crashes and hard to diagnose problems with your application.

Definition at line 102 of file SDL.c.

References SDL_MainIsReady, and SDL_TRUE.

{
SDL_MainIsReady = SDL_TRUE;
}
SDL_MainIsReady
static SDL_bool SDL_MainIsReady
Definition: SDL.c:54
SDL_TRUE
Definition: SDL_stdinc.h:129

void SDL_TicksInit | ( | void |  | ) |

Referenced by SDL_InitSubSystem(), and SDL_VideoInit().

void SDL_TicksQuit | ( | void |  | ) |

Referenced by SDL_Quit().

int SDL_TimerInit | ( | void |  | ) |

Definition at line 206 of file SDL_timer.c.

Referenced by SDL_InitSubSystem().

{
SDL_TimerData *data = &SDL_timer_data;
if (!data->active) {
const char *name = "SDLTimer";
data->timermap_lock = SDL_CreateMutex();
if (!data->timermap_lock) {
return -1;
}
data->sem = SDL_CreateSemaphore(0);
if (!data->sem) {
SDL_DestroyMutex(data->timermap_lock);
return -1;
}
data->active = SDL_TRUE;
/* !!! FIXME: this is nasty. */
#if defined(__WIN32__) && !defined(HAVE_LIBC)
#undef SDL_CreateThread
#if SDL_DYNAMIC_API
data->thread = SDL_CreateThread_REAL(SDL_TimerThread, name, data, NULL, NULL);
#else
data->thread = SDL_CreateThread(SDL_TimerThread, name, data, NULL, NULL);
#endif
#else
data->thread = SDL_CreateThread(SDL_TimerThread, name, data);
#endif
if (!data->thread) {
SDL_TimerQuit();
return -1;
}
SDL_AtomicSet(&data->nextID, 1);
}
return 0;
}
SDL_TimerThread
static int SDL_TimerThread(void *_data)
Definition: SDL_timer.c:101
SDL_TimerQuit
void SDL_TimerQuit(void)
Definition: SDL_timer.c:246
SDL_CreateSemaphore
#define SDL_CreateSemaphore
Definition: SDL_dynapi_overrides.h:270
SDL_CreateMutex
#define SDL_CreateMutex
Definition: SDL_dynapi_overrides.h:265
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_TimerData::thread
SDL_Thread * thread
Definition: SDL_timer.c:52
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_TimerData::nextID
SDL_atomic_t nextID
Definition: SDL_timer.c:53
SDL_TimerData::active
volatile SDL_bool active
Definition: SDL_timer.c:65
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_TimerData::sem
SDL_sem * sem
Definition: SDL_timer.c:62
SDL_CreateThread
#define SDL_CreateThread
Definition: SDL_dynapi_overrides.h:47
NULL
#define NULL
Definition: begin_code.h:143
SDL_TimerData::timermap_lock
SDL_mutex * timermap_lock
Definition: SDL_timer.c:55
SDL_DestroyMutex
#define SDL_DestroyMutex
Definition: SDL_dynapi_overrides.h:269
SDL_timer_data
static SDL_TimerData SDL_timer_data
Definition: SDL_timer.c:71
SDL_AtomicSet
#define SDL_AtomicSet
Definition: SDL_dynapi_overrides.h:73
SDL_TimerData
Definition: SDL_timer.c:50

void SDL_TimerQuit | ( | void |  | ) |

Definition at line 246 of file SDL_timer.c.

Referenced by SDL_QuitSubSystem().

{
SDL_TimerData *data = &SDL_timer_data;
SDL_Timer *timer;
SDL_TimerMap *entry;
if (data->active) {
data->active = SDL_FALSE;
/* Shutdown the timer thread */
if (data->thread) {
SDL_SemPost(data->sem);
SDL_WaitThread(data->thread, NULL);
data->thread = NULL;
}
SDL_DestroySemaphore(data->sem);
data->sem = NULL;
/* Clean up the timer entries */
while (data->timers) {
timer = data->timers;
data->timers = timer->next;
SDL_free(timer);
}
while (data->freelist) {
timer = data->freelist;
data->freelist = timer->next;
SDL_free(timer);
}
while (data->timermap) {
entry = data->timermap;
data->timermap = entry->next;
SDL_free(entry);
}
SDL_DestroyMutex(data->timermap_lock);
data->timermap_lock = NULL;
}
}
SDL_TimerData::timermap
SDL_TimerMap * timermap
Definition: SDL_timer.c:54
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_TimerData::thread
SDL_Thread * thread
Definition: SDL_timer.c:52
SDL_TimerData::active
volatile SDL_bool active
Definition: SDL_timer.c:65
SDL_SemPost
#define SDL_SemPost
Definition: SDL_dynapi_overrides.h:275
SDL_TimerMap
Definition: SDL_timer.c:42
SDL_TimerData::freelist
SDL_Timer *volatile freelist
Definition: SDL_timer.c:64
SDL_Timer::next
struct _SDL_Timer * next
Definition: SDL_timer.c:39
SDL_free
void SDL_free(void *mem)
SDL_TimerData::sem
SDL_sem * sem
Definition: SDL_timer.c:62
SDL_TimerMap::next
struct _SDL_TimerMap * next
Definition: SDL_timer.c:46
NULL
#define NULL
Definition: begin_code.h:143
SDL_TimerData::timermap_lock
SDL_mutex * timermap_lock
Definition: SDL_timer.c:55
SDL_DestroyMutex
#define SDL_DestroyMutex
Definition: SDL_dynapi_overrides.h:269
SDL_Timer
Definition: SDL_timer.c:31
SDL_DestroySemaphore
#define SDL_DestroySemaphore
Definition: SDL_dynapi_overrides.h:271
SDL_timer_data
static SDL_TimerData SDL_timer_data
Definition: SDL_timer.c:71
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_TimerData::timers
SDL_Timer * timers
Definition: SDL_timer.c:68
SDL_TimerData
Definition: SDL_timer.c:50
SDL_WaitThread
#define SDL_WaitThread
Definition: SDL_dynapi_overrides.h:482

Uint32 SDL_WasInit | ( | Uint32 | flags | ) |

This function returns a mask of the specified subsystems which have previously been initialized.

If `flags` is 0, it returns a mask of all initialized subsystems.

Definition at line 324 of file SDL.c.

References i, SDL_arraysize, SDL_INIT_EVERYTHING, SDL_min, SDL_MostSignificantBitIndex32(), and SDL_SubsystemRefCount.

{
int i;
int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
Uint32 initialized = 0;
if (!flags) {
flags = SDL_INIT_EVERYTHING;
}
num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
/* Iterate over each bit in flags, and check the matching subsystem. */
for (i = 0; i < num_subsystems; ++i) {
if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
initialized |= (1 << i);
}
flags >>= 1;
}
return initialized;
}
SDL_min
#define SDL_min(x, y)
Definition: SDL_stdinc.h:347
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_SubsystemRefCount
static Uint8 SDL_SubsystemRefCount[32]
Definition: SDL.c:57
SDL_MostSignificantBitIndex32
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
Definition: SDL_bits.h:51
SDL_INIT_EVERYTHING
#define SDL_INIT_EVERYTHING
Definition: SDL.h:83
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480

## Variable Documentation

SDL_bool SDL_bInMainQuit = SDL_FALSE

static

Definition at line 56 of file SDL.c.

Referenced by SDL_PrivateShouldQuitSubsystem(), and SDL_Quit().

SDL_bool SDL_MainIsReady = SDL_TRUE

static

Definition at line 54 of file SDL.c.

Referenced by SDL_InitSubSystem(), and SDL_SetMainReady().

Uint8 SDL_SubsystemRefCount[32]

static

Definition at line 57 of file SDL.c.

Referenced by SDL_PrivateShouldInitSubsystem(), SDL_PrivateShouldQuitSubsystem(), SDL_PrivateSubsystemRefCountDecr(), SDL_PrivateSubsystemRefCountIncr(), SDL_Quit(), and SDL_WasInit().