SDL  2.0
SDL_sysmutex.cpp File Reference
#include "../../SDL_internal.h"
#include "SDL_thread.h"
#include "SDL_systhread_c.h"
#include "SDL_log.h"
#include <system_error>
#include "SDL_sysmutex_c.h"
#include <Windows.h>
+ Include dependency graph for SDL_sysmutex.cpp:

Go to the source code of this file.

Functions

SDL_mutexSDL_CreateMutex (void)
void SDL_DestroyMutex (SDL_mutex *mutex)
int SDL_mutexP (SDL_mutex *mutex)
int SDL_TryLockMutex (SDL_mutex *mutex)
int SDL_mutexV (SDL_mutex *mutex)

Function Documentation

SDL_mutex* SDL_CreateMutex ( void  )

Create a mutex, initialized unlocked.

Definition at line 38 of file SDL_sysmutex.cpp.

References mutex, NULL, SDL_OutOfMemory, and SDL_SetError.

{
/* Allocate and initialize the mutex */
try {
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 &) {
return NULL;
}
}
void SDL_DestroyMutex ( SDL_mutex mutex)

Destroy a mutex.

Definition at line 56 of file SDL_sysmutex.cpp.

References mutex.

{
if (mutex) {
delete mutex;
}
}
int SDL_mutexP ( SDL_mutex mutex)

Definition at line 66 of file SDL_sysmutex.cpp.

References SDL_mutex::cpp_mutex, NULL, and SDL_SetError.

{
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
}
try {
mutex->cpp_mutex.lock();
return 0;
} catch (std::system_error & ex) {
SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
return -1;
}
}
int SDL_mutexV ( SDL_mutex mutex)

Definition at line 100 of file SDL_sysmutex.cpp.

References SDL_mutex::cpp_mutex, NULL, and SDL_SetError.

{
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
}
mutex->cpp_mutex.unlock();
return 0;
}
int SDL_TryLockMutex ( SDL_mutex mutex)

Try to lock the mutex

Returns
0, SDL_MUTEX_TIMEDOUT, or -1 on error

Definition at line 84 of file SDL_sysmutex.cpp.

References SDL_mutex::cpp_mutex, NULL, retval, SDL_MUTEX_TIMEDOUT, and SDL_SetError.

{
int retval = 0;
if (mutex == NULL) {
return SDL_SetError("Passed a NULL mutex");
}
if (mutex->cpp_mutex.try_lock() == false) {
}
return retval;
}