mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-12 21:06:01 +00:00
Add SDL_cond implementation using Windows Condition Variables
Is automatically used when the SRW SDL_mutex implementation is active. Otherwise falls back to the generic implementation. v2: - Rebase onto master fa3ea1051a4b
This commit is contained in:
@@ -31,41 +31,19 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_mutex.h"
|
||||
|
||||
typedef SDL_mutex * (*pfnSDL_CreateMutex)(void);
|
||||
typedef int (*pfnSDL_LockMutex)(SDL_mutex *);
|
||||
typedef int (*pfnSDL_TryLockMutex)(SDL_mutex *);
|
||||
typedef int (*pfnSDL_UnlockMutex)(SDL_mutex *);
|
||||
typedef void (*pfnSDL_DestroyMutex)(SDL_mutex *);
|
||||
#include "SDL_sysmutex_c.h"
|
||||
|
||||
typedef struct SDL_mutex_impl_t
|
||||
{
|
||||
pfnSDL_CreateMutex Create;
|
||||
pfnSDL_DestroyMutex Destroy;
|
||||
pfnSDL_LockMutex Lock;
|
||||
pfnSDL_TryLockMutex TryLock;
|
||||
pfnSDL_UnlockMutex Unlock;
|
||||
} SDL_mutex_impl_t;
|
||||
|
||||
/* Implementation will be chosen at runtime based on available Kernel features */
|
||||
static SDL_mutex_impl_t SDL_mutex_impl_active = {0};
|
||||
SDL_mutex_impl_t SDL_mutex_impl_active = {0};
|
||||
|
||||
|
||||
/**
|
||||
* Implementation based on Slim Reader/Writer (SRW) Locks for Win 7 and newer.
|
||||
*/
|
||||
|
||||
#ifndef SRWLOCK_INIT
|
||||
#define SRWLOCK_INIT {0}
|
||||
typedef struct _SRWLOCK {
|
||||
PVOID Ptr;
|
||||
} SRWLOCK, *PSRWLOCK;
|
||||
#endif
|
||||
|
||||
#if __WINRT__
|
||||
/* Functions are guaranteed to be available */
|
||||
#define pReleaseSRWLockExclusive ReleaseSRWLockExclusive
|
||||
@@ -80,14 +58,6 @@ static pfnAcquireSRWLockExclusive pAcquireSRWLockExclusive = NULL;
|
||||
static pfnTryAcquireSRWLockExclusive pTryAcquireSRWLockExclusive = NULL;
|
||||
#endif
|
||||
|
||||
typedef struct SDL_mutex_srw
|
||||
{
|
||||
SRWLOCK srw;
|
||||
/* SRW Locks are not recursive, that has to be handled by SDL: */
|
||||
DWORD count;
|
||||
DWORD owner;
|
||||
} SDL_mutex_srw;
|
||||
|
||||
static SDL_mutex *
|
||||
SDL_CreateMutex_srw(void)
|
||||
{
|
||||
@@ -189,6 +159,7 @@ static const SDL_mutex_impl_t SDL_mutex_impl_srw =
|
||||
&SDL_LockMutex_srw,
|
||||
&SDL_TryLockMutex_srw,
|
||||
&SDL_UnlockMutex_srw,
|
||||
SDL_MUTEX_SRW,
|
||||
};
|
||||
|
||||
|
||||
@@ -283,6 +254,7 @@ static const SDL_mutex_impl_t SDL_mutex_impl_cs =
|
||||
&SDL_LockMutex_cs,
|
||||
&SDL_TryLockMutex_cs,
|
||||
&SDL_UnlockMutex_cs,
|
||||
SDL_MUTEX_CS,
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user