raze-gles/polymer/eduke32/build/src/mutex.c
helixhorned 830f73a316 Patch adding Wii support by tueidj, part 6: mutexes
For the Wii, SDL's mutex functionality is used.  The implementation in the
original patch was wrong though, so this part required non-trivial changes.

git-svn-id: https://svn.eduke32.com/eduke32@2626 1a8010ca-5511-0410-912e-c29ae57300e0
2012-05-01 12:39:20 +00:00

42 lines
797 B
C

#include "compat.h"
#include "mutex.h"
int32_t mutex_init(mutex_t *mutex)
{
#ifdef _WIN32
*mutex = CreateMutex(0, FALSE, 0);
return (*mutex == 0);
#elif !defined GEKKO
return pthread_mutex_init(mutex, NULL);
#else
if (mutex)
{
*mutex = SDL_CreateMutex();
if (*mutex != NULL)
return 0;
}
return -1;
#endif
}
int32_t mutex_lock(mutex_t *mutex)
{
#ifdef _WIN32
return (WaitForSingleObject(*mutex, INFINITE) == WAIT_FAILED);
#elif !defined GEKKO
return pthread_mutex_lock(mutex);
#else
return SDL_LockMutex(*mutex);
#endif
}
int32_t mutex_unlock(mutex_t *mutex)
{
#ifdef _WIN32
return (ReleaseMutex(*mutex) == 0);
#elif !defined GEKKO
return pthread_mutex_unlock(mutex);
#else
return SDL_UnlockMutex(*mutex);
#endif
}