mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-26 03:30:46 +00:00
Re-implement our mutex_lock() family of functions using SDL's atomic spinlocks
git-svn-id: https://svn.eduke32.com/eduke32@7907 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
aec48c73c1
commit
064516c050
2 changed files with 11 additions and 16 deletions
|
@ -19,12 +19,12 @@ typedef HANDLE mutex_t;
|
||||||
#else
|
#else
|
||||||
/* PK: I don't like pointer typedefs, but SDL_CreateMutex() _returns_ one,
|
/* PK: I don't like pointer typedefs, but SDL_CreateMutex() _returns_ one,
|
||||||
* so we're out of luck with our interface. */
|
* so we're out of luck with our interface. */
|
||||||
typedef SDL_mutex* mutex_t;
|
typedef SDL_SpinLock mutex_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int32_t mutex_init(mutex_t *mutex);
|
extern int32_t mutex_init(mutex_t *mutex);
|
||||||
extern int32_t mutex_lock(mutex_t *mutex);
|
extern void mutex_lock(mutex_t *mutex);
|
||||||
extern int32_t mutex_unlock(mutex_t *mutex);
|
extern void mutex_unlock(mutex_t *mutex);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -13,30 +13,25 @@ int32_t mutex_init(mutex_t *mutex)
|
||||||
*mutex = CreateMutex(0, FALSE, 0);
|
*mutex = CreateMutex(0, FALSE, 0);
|
||||||
return (*mutex == 0);
|
return (*mutex == 0);
|
||||||
#else
|
#else
|
||||||
if (mutex)
|
*mutex = 0;
|
||||||
{
|
|
||||||
*mutex = SDL_CreateMutex();
|
|
||||||
if (*mutex != NULL)
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mutex_lock(mutex_t *mutex)
|
void mutex_lock(mutex_t *mutex)
|
||||||
{
|
{
|
||||||
#ifdef RENDERTYPEWIN
|
#ifdef RENDERTYPEWIN
|
||||||
return (WaitForSingleObject(*mutex, INFINITE) == WAIT_FAILED);
|
return WaitForSingleObject(*mutex, INFINITE);
|
||||||
#else
|
#else
|
||||||
return SDL_LockMutex(*mutex);
|
return SDL_AtomicLock(mutex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mutex_unlock(mutex_t *mutex)
|
void mutex_unlock(mutex_t *mutex)
|
||||||
{
|
{
|
||||||
#ifdef RENDERTYPEWIN
|
#ifdef RENDERTYPEWIN
|
||||||
return (ReleaseMutex(*mutex) == 0);
|
ReleaseMutex(*mutex);
|
||||||
#else
|
#else
|
||||||
return SDL_UnlockMutex(*mutex);
|
SDL_AtomicUnlock(mutex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue