mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-14 13:56:00 +00:00
hints: Change hints to be backed by Properties, add documentation. (#9892)
This makes the subsystem thread-safe, more performant, and cleans up the code a little. Also removed SDL_HINT_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS, since setting this hint programmatically initializes properties, which creates a lock, so we can't check hints while creating locks. The slim reader-writer locks have been the default for ages and are solid, so we'll just use those when available.
This commit is contained in:
@@ -194,29 +194,25 @@ static const SDL_mutex_impl_t SDL_mutex_impl_cs = {
|
||||
SDL_Mutex *SDL_CreateMutex(void)
|
||||
{
|
||||
if (!SDL_mutex_impl_active.Create) {
|
||||
// Default to fallback implementation
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
const SDL_mutex_impl_t *impl = &SDL_mutex_impl_srw;
|
||||
#else
|
||||
const SDL_mutex_impl_t *impl = &SDL_mutex_impl_cs;
|
||||
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS, SDL_FALSE)) {
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
// Link statically on this platform
|
||||
impl = &SDL_mutex_impl_srw;
|
||||
#else
|
||||
// Try faster implementation for Windows 7 and newer
|
||||
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
|
||||
if (kernel32) {
|
||||
// Requires Vista:
|
||||
pInitializeSRWLock = (pfnInitializeSRWLock)GetProcAddress(kernel32, "InitializeSRWLock");
|
||||
pReleaseSRWLockExclusive = (pfnReleaseSRWLockExclusive)GetProcAddress(kernel32, "ReleaseSRWLockExclusive");
|
||||
pAcquireSRWLockExclusive = (pfnAcquireSRWLockExclusive)GetProcAddress(kernel32, "AcquireSRWLockExclusive");
|
||||
// Requires 7:
|
||||
pTryAcquireSRWLockExclusive = (pfnTryAcquireSRWLockExclusive)GetProcAddress(kernel32, "TryAcquireSRWLockExclusive");
|
||||
if (pInitializeSRWLock && pReleaseSRWLockExclusive && pAcquireSRWLockExclusive && pTryAcquireSRWLockExclusive) {
|
||||
impl = &SDL_mutex_impl_srw;
|
||||
}
|
||||
// Try faster implementation for Windows 7 and newer
|
||||
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
|
||||
if (kernel32) {
|
||||
// Requires Vista:
|
||||
pInitializeSRWLock = (pfnInitializeSRWLock)GetProcAddress(kernel32, "InitializeSRWLock");
|
||||
pReleaseSRWLockExclusive = (pfnReleaseSRWLockExclusive)GetProcAddress(kernel32, "ReleaseSRWLockExclusive");
|
||||
pAcquireSRWLockExclusive = (pfnAcquireSRWLockExclusive)GetProcAddress(kernel32, "AcquireSRWLockExclusive");
|
||||
// Requires 7:
|
||||
pTryAcquireSRWLockExclusive = (pfnTryAcquireSRWLockExclusive)GetProcAddress(kernel32, "TryAcquireSRWLockExclusive");
|
||||
if (pInitializeSRWLock && pReleaseSRWLockExclusive && pAcquireSRWLockExclusive && pTryAcquireSRWLockExclusive) {
|
||||
impl = &SDL_mutex_impl_srw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif // SDL_PLATFORM_WINRT
|
||||
|
||||
// Copy instead of using pointer to save one level of indirection
|
||||
SDL_copyp(&SDL_mutex_impl_active, impl);
|
||||
|
Reference in New Issue
Block a user