#include "../../SDL_internal.h"
extern "C" {
#include "SDL_thread.h"
#include "SDL_systhread_c.h"
}
#include <system_error>
#include "SDL_sysmutex_c.h"
#include <Windows.h>
extern "C"
SDL_mutex *
SDL_CreateMutex(void)
{
try {
SDL_mutex * mutex = new SDL_mutex;
return mutex;
} catch (std::system_error & ex) {
SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what());
return NULL;
} catch (std::bad_alloc &) {
SDL_OutOfMemory();
return NULL;
}
}
extern "C"
void
SDL_DestroyMutex(SDL_mutex * mutex)
{
if (mutex) {
delete mutex;
}
}
extern "C"
int
SDL_mutexP(SDL_mutex * mutex)
{
if (mutex == NULL) {
return SDL_InvalidParamError("mutex");
}
try {
mutex->cpp_mutex.lock();
return 0;
} catch (std::system_error & ex) {
return SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
}
}
int
SDL_TryLockMutex(SDL_mutex * mutex)
{
int retval = 0;
if (mutex == NULL) {
return SDL_InvalidParamError("mutex");
}
if (mutex->cpp_mutex.try_lock() == false) {
retval = SDL_MUTEX_TIMEDOUT;
}
return retval;
}
extern "C"
int
SDL_mutexV(SDL_mutex * mutex)
{
if (mutex == NULL) {
return SDL_InvalidParamError("mutex");
}
mutex->cpp_mutex.unlock();
return 0;
}