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.

References mutex, NULL, SDL_OutOfMemory, and SDL_SetError.

39 {
40  /* Allocate and initialize the mutex */
41  try {
42  SDL_mutex * mutex = new SDL_mutex;
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 }
static SDL_mutex * mutex
Definition: testlock.c:23
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError

◆ SDL_DestroyMutex()

void SDL_DestroyMutex ( SDL_mutex mutex)

Destroy a mutex.

Definition at line 56 of file SDL_sysmutex.cpp.

References mutex.

57 {
58  if (mutex) {
59  delete mutex;
60  }
61 }
static SDL_mutex * mutex
Definition: testlock.c:23

◆ SDL_mutexP()

int SDL_mutexP ( SDL_mutex mutex)

Definition at line 66 of file SDL_sysmutex.cpp.

References SDL_mutex::cpp_mutex, NULL, and SDL_SetError.

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
#define NULL
Definition: begin_code.h:164
#define SDL_SetError

◆ SDL_mutexV()

int SDL_mutexV ( SDL_mutex mutex)

Definition at line 100 of file SDL_sysmutex.cpp.

References SDL_mutex::cpp_mutex, NULL, and SDL_SetError.

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 }
std::recursive_mutex cpp_mutex
#define NULL
Definition: begin_code.h:164
#define 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.

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

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) {
92  retval = SDL_MUTEX_TIMEDOUT;
93  }
94  return retval;
95 }
std::recursive_mutex cpp_mutex
#define SDL_MUTEX_TIMEDOUT
Definition: SDL_mutex.h:44
SDL_bool retval
#define NULL
Definition: begin_code.h:164
#define SDL_SetError