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_mutex * | SDL_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 {
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;
}
}
mutex
static SDL_mutex * mutex
Definition: testlock.c:23
SDL_mutex
Definition: SDL_sysmutex.c:29
NULL
#define NULL
Definition: begin_code.h:143
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

void SDL_DestroyMutex | ( | SDL_mutex * | mutex | ) |

Destroy a mutex.

Definition at line 56 of file SDL_sysmutex.cpp.

References mutex.

{
if (mutex) {
delete mutex;
}
}
mutex
static SDL_mutex * mutex
Definition: testlock.c:23

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;
}
}
SDL_mutex::cpp_mutex
std::recursive_mutex cpp_mutex
Definition: SDL_sysmutex_c.h:27
NULL
#define NULL
Definition: begin_code.h:143
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

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;
}
SDL_mutex::cpp_mutex
std::recursive_mutex cpp_mutex
Definition: SDL_sysmutex_c.h:27
NULL
#define NULL
Definition: begin_code.h:143
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

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) {
retval = SDL_MUTEX_TIMEDOUT;
}
return retval;
}
SDL_mutex::cpp_mutex
std::recursive_mutex cpp_mutex
Definition: SDL_sysmutex_c.h:27
SDL_MUTEX_TIMEDOUT
#define SDL_MUTEX_TIMEDOUT
Definition: SDL_mutex.h:44
retval
SDL_bool retval
Definition: testgamecontroller.c:65
NULL
#define NULL
Definition: begin_code.h:143
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36