mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-26 12:27:44 +00:00
Allow initializing hints and properties from any thread
This commit is contained in:
@@ -36,20 +36,37 @@ typedef struct SDL_Hint
|
||||
SDL_HintWatch *callbacks;
|
||||
} SDL_Hint;
|
||||
|
||||
static SDL_PropertiesID SDL_hint_props = 0;
|
||||
static SDL_AtomicU32 SDL_hint_props;
|
||||
|
||||
static SDL_PropertiesID GetHintProperties(bool create)
|
||||
{
|
||||
if (!SDL_hint_props && create) {
|
||||
SDL_hint_props = SDL_CreateProperties();
|
||||
}
|
||||
return SDL_hint_props;
|
||||
}
|
||||
|
||||
void SDL_InitHints(void)
|
||||
{
|
||||
// Just make sure the hint properties are created on the main thread
|
||||
(void)GetHintProperties(true);
|
||||
}
|
||||
|
||||
void SDL_QuitHints(void)
|
||||
{
|
||||
SDL_PropertiesID props;
|
||||
do {
|
||||
props = SDL_GetAtomicU32(&SDL_hint_props);
|
||||
} while (!SDL_CompareAndSwapAtomicU32(&SDL_hint_props, props, 0));
|
||||
|
||||
if (props) {
|
||||
SDL_DestroyProperties(props);
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_PropertiesID GetHintProperties(bool create)
|
||||
{
|
||||
SDL_PropertiesID props = SDL_GetAtomicU32(&SDL_hint_props);
|
||||
if (!props && create) {
|
||||
props = SDL_CreateProperties();
|
||||
if (!SDL_CompareAndSwapAtomicU32(&SDL_hint_props, 0, props)) {
|
||||
// Somebody else created hint properties before us, just use those
|
||||
SDL_DestroyProperties(props);
|
||||
props = SDL_GetAtomicU32(&SDL_hint_props);
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
static void SDLCALL CleanupHintProperty(void *userdata, void *value)
|
||||
@@ -336,9 +353,3 @@ void SDL_RemoveHintCallback(const char *name, SDL_HintCallback callback, void *u
|
||||
SDL_UnlockProperties(hints);
|
||||
}
|
||||
|
||||
void SDL_QuitHints(void)
|
||||
{
|
||||
SDL_DestroyProperties(SDL_hint_props);
|
||||
SDL_hint_props = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user