2010-05-02 23:27:30 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "mutex.h"
|
|
|
|
|
|
|
|
int32_t mutex_init(mutex_t *mutex)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
*mutex = CreateMutex(0, FALSE, 0);
|
|
|
|
return (*mutex == 0);
|
2012-05-01 12:39:20 +00:00
|
|
|
#elif !defined GEKKO
|
2010-05-02 23:27:30 +00:00
|
|
|
return pthread_mutex_init(mutex, NULL);
|
2012-05-01 12:39:20 +00:00
|
|
|
#else
|
|
|
|
if (mutex)
|
|
|
|
{
|
|
|
|
*mutex = SDL_CreateMutex();
|
|
|
|
if (*mutex != NULL)
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
return -1;
|
2012-05-01 12:39:20 +00:00
|
|
|
#endif
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t mutex_lock(mutex_t *mutex)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return (WaitForSingleObject(*mutex, INFINITE) == WAIT_FAILED);
|
2012-05-01 12:39:20 +00:00
|
|
|
#elif !defined GEKKO
|
2010-05-02 23:27:30 +00:00
|
|
|
return pthread_mutex_lock(mutex);
|
2012-05-01 12:39:20 +00:00
|
|
|
#else
|
|
|
|
return SDL_LockMutex(*mutex);
|
2010-05-02 23:27:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t mutex_unlock(mutex_t *mutex)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return (ReleaseMutex(*mutex) == 0);
|
2012-05-01 12:39:20 +00:00
|
|
|
#elif !defined GEKKO
|
2010-05-02 23:27:30 +00:00
|
|
|
return pthread_mutex_unlock(mutex);
|
2012-05-01 12:39:20 +00:00
|
|
|
#else
|
|
|
|
return SDL_UnlockMutex(*mutex);
|
2010-05-02 23:27:30 +00:00
|
|
|
#endif
|
|
|
|
}
|