2010-05-02 23:27:30 +00:00
|
|
|
#include "compat.h"
|
2017-02-19 22:15:44 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# define NEED_PROCESS_H
|
|
|
|
# include "windows_inc.h"
|
|
|
|
#endif
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
#include "mutex.h"
|
|
|
|
|
|
|
|
int32_t mutex_init(mutex_t *mutex)
|
|
|
|
{
|
2014-04-17 19:58:07 +00:00
|
|
|
#ifdef RENDERTYPEWIN
|
2010-05-02 23:27:30 +00:00
|
|
|
*mutex = CreateMutex(0, FALSE, 0);
|
|
|
|
return (*mutex == 0);
|
2012-05-01 12:39:20 +00:00
|
|
|
#else
|
2019-08-07 22:43:57 +00:00
|
|
|
*mutex = 0;
|
|
|
|
return 0;
|
2012-05-01 12:39:20 +00:00
|
|
|
#endif
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 22:43:57 +00:00
|
|
|
void mutex_lock(mutex_t *mutex)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2014-04-17 19:58:07 +00:00
|
|
|
#ifdef RENDERTYPEWIN
|
2019-08-13 02:53:34 +00:00
|
|
|
WaitForSingleObject(*mutex, INFINITE);
|
2012-05-01 12:39:20 +00:00
|
|
|
#else
|
2019-08-13 02:53:34 +00:00
|
|
|
SDL_AtomicLock(mutex);
|
2010-05-02 23:27:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-08-07 22:43:57 +00:00
|
|
|
void mutex_unlock(mutex_t *mutex)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2014-04-17 19:58:07 +00:00
|
|
|
#ifdef RENDERTYPEWIN
|
2019-08-07 22:43:57 +00:00
|
|
|
ReleaseMutex(*mutex);
|
2012-05-01 12:39:20 +00:00
|
|
|
#else
|
2019-08-07 22:43:57 +00:00
|
|
|
SDL_AtomicUnlock(mutex);
|
2010-05-02 23:27:30 +00:00
|
|
|
#endif
|
|
|
|
}
|