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_CreateMutex()

SDL_mutex * SDL_CreateMutex ( void  )

Create a mutex, initialized unlocked.

Definition at line 38 of file SDL_sysmutex.cpp.

39{
40 /* Allocate and initialize the mutex */
41 try {
43 return mutex;
44 } catch (std::system_error & ex) {
45 SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what());
46 return NULL;
47 } catch (std::bad_alloc &) {
49 return NULL;
50 }
51}
#define SDL_SetError
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define NULL
Definition: begin_code.h:167
static SDL_mutex * mutex
Definition: testlock.c:23

References mutex, NULL, SDL_mutex::owner, SDL_mutex::recursive, SDL_CreateSemaphore, SDL_free, SDL_malloc, SDL_OutOfMemory, SDL_SetError, and SDL_mutex::sem.

◆ SDL_DestroyMutex()

void SDL_DestroyMutex ( SDL_mutex mutex)

Destroy a mutex.

Definition at line 56 of file SDL_sysmutex.cpp.

57{
58 if (mutex) {
59 delete mutex;
60 }
61}

References mutex, SDL_DestroySemaphore, SDL_free, and SDL_mutex::sem.

◆ SDL_mutexP()

int SDL_mutexP ( SDL_mutex mutex)

Definition at line 66 of file SDL_sysmutex.cpp.

67{
68 if (mutex == NULL) {
69 SDL_SetError("Passed a NULL mutex");
70 return -1;
71 }
72
73 try {
74 mutex->cpp_mutex.lock();
75 return 0;
76 } catch (std::system_error & ex) {
77 SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
78 return -1;
79 }
80}
std::recursive_mutex cpp_mutex

References SDL_mutex::cpp_mutex, mutex, NULL, and SDL_SetError.

◆ SDL_mutexV()

int SDL_mutexV ( SDL_mutex mutex)

Definition at line 100 of file SDL_sysmutex.cpp.

101{
102 if (mutex == NULL) {
103 SDL_SetError("Passed a NULL mutex");
104 return -1;
105 }
106
107 mutex->cpp_mutex.unlock();
108 return 0;
109}

References SDL_mutex::cpp_mutex, mutex, NULL, and SDL_SetError.

◆ SDL_TryLockMutex()

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.

85{
86 int retval = 0;
87 if (mutex == NULL) {
88 return SDL_SetError("Passed a NULL mutex");
89 }
90
91 if (mutex->cpp_mutex.try_lock() == false) {
93 }
94 return retval;
95}
#define SDL_MUTEX_TIMEDOUT
Definition: SDL_mutex.h:44
SDL_bool retval

References SDL_mutex::cpp_mutex, mutex, NULL, SDL_mutex::owner, SDL_mutex::recursive, retval, SDL_MUTEX_TIMEDOUT, SDL_SemWait, SDL_SetError, SDL_ThreadID, and SDL_mutex::sem.