SDL  2.0
SDL_sysmutex.cpp File Reference
#include "../../SDL_internal.h"
#include "SDL_thread.h"
#include "SDL_systhread_c.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 37 of file SDL_sysmutex.cpp.

38 {
39  /* Allocate and initialize the mutex */
40  try {
41  SDL_mutex * mutex = new SDL_mutex;
42  return mutex;
43  } catch (std::system_error & ex) {
44  SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what());
45  return NULL;
46  } catch (std::bad_alloc &) {
48  return NULL;
49  }
50 }
#define SDL_SetError
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
#define NULL
Definition: begin_code.h:163
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 55 of file SDL_sysmutex.cpp.

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

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

◆ SDL_mutexP()

int SDL_mutexP ( SDL_mutex mutex)

Definition at line 65 of file SDL_sysmutex.cpp.

66 {
67  if (mutex == NULL) {
68  SDL_SetError("Passed a NULL mutex");
69  return -1;
70  }
71 
72  try {
73  mutex->cpp_mutex.lock();
74  return 0;
75  } catch (std::system_error & ex) {
76  SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
77  return -1;
78  }
79 }
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 99 of file SDL_sysmutex.cpp.

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

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 83 of file SDL_sysmutex.cpp.

84 {
85  int retval = 0;
86  if (mutex == NULL) {
87  return SDL_SetError("Passed a NULL mutex");
88  }
89 
90  if (mutex->cpp_mutex.try_lock() == false) {
92  }
93  return retval;
94 }
#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.