mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
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
This commit is contained in:
parent
f775faf435
commit
830f73a316
2 changed files with 27 additions and 12 deletions
|
@ -1,17 +1,25 @@
|
|||
#ifndef __mutex_h__
|
||||
#define __mutex_h__
|
||||
|
||||
/* Mutual exclusion mechanism wrappers for the different platforms */
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
# include <windows.h>
|
||||
# include <process.h>
|
||||
#elif !defined GEKKO
|
||||
# include <pthread.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
# include <SDL.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
typedef HANDLE mutex_t;
|
||||
#else
|
||||
#elif !defined GEKKO
|
||||
typedef pthread_mutex_t mutex_t;
|
||||
#else
|
||||
/* PK: I don't like pointer typedefs, but SDL_CreateMutex() _returns_ one,
|
||||
* so we're out of luck with our interface. */
|
||||
typedef SDL_mutex* mutex_t;
|
||||
#endif
|
||||
|
||||
extern int32_t mutex_init(mutex_t *mutex);
|
||||
|
|
|
@ -6,30 +6,37 @@ int32_t mutex_init(mutex_t *mutex)
|
|||
#ifdef _WIN32
|
||||
*mutex = CreateMutex(0, FALSE, 0);
|
||||
return (*mutex == 0);
|
||||
#else
|
||||
#elif !defined GEKKO
|
||||
return pthread_mutex_init(mutex, NULL);
|
||||
#endif
|
||||
#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);
|
||||
#else
|
||||
#elif !defined GEKKO
|
||||
return pthread_mutex_lock(mutex);
|
||||
#else
|
||||
return SDL_LockMutex(*mutex);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mutex_unlock(mutex_t *mutex)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return (ReleaseMutex(*mutex) == 0);
|
||||
#else
|
||||
#elif !defined GEKKO
|
||||
return pthread_mutex_unlock(mutex);
|
||||
#else
|
||||
return SDL_UnlockMutex(*mutex);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue