SDL  2.0
SDL_error_c.h File Reference
#include "./SDL_internal.h"
+ Include dependency graph for SDL_error_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_error
 

Macros

#define ERR_MAX_STRLEN   128
 
#define ERR_MAX_ARGS   5
 

Functions

SDL_errorSDL_GetErrBuf (void)
 

Macro Definition Documentation

#define ERR_MAX_ARGS   5

Definition at line 31 of file SDL_error_c.h.

Referenced by SDL_SetError().

#define ERR_MAX_STRLEN   128

Definition at line 30 of file SDL_error_c.h.

Referenced by SDL_SetError().

Function Documentation

SDL_error* SDL_GetErrBuf ( void  )

Definition at line 205 of file SDL_thread.c.

References NULL, SDL_AtomicLock, SDL_AtomicUnlock, SDL_FALSE, SDL_free(), SDL_malloc, SDL_MemoryBarrierAcquire, SDL_MemoryBarrierRelease, SDL_TLSCreate(), SDL_TLSGet(), SDL_TLSSet(), SDL_TRUE, and SDL_zerop.

206 {
207  static SDL_SpinLock tls_lock;
208  static SDL_bool tls_being_created;
209  static SDL_TLSID tls_errbuf;
210  static SDL_error SDL_global_errbuf;
211  const SDL_error *ALLOCATION_IN_PROGRESS = (SDL_error *)-1;
212  SDL_error *errbuf;
213 
214  /* tls_being_created is there simply to prevent recursion if SDL_TLSCreate() fails.
215  It also means it's possible for another thread to also use SDL_global_errbuf,
216  but that's very unlikely and hopefully won't cause issues.
217  */
218  if (!tls_errbuf && !tls_being_created) {
219  SDL_AtomicLock(&tls_lock);
220  if (!tls_errbuf) {
221  SDL_TLSID slot;
222  tls_being_created = SDL_TRUE;
223  slot = SDL_TLSCreate();
224  tls_being_created = SDL_FALSE;
226  tls_errbuf = slot;
227  }
228  SDL_AtomicUnlock(&tls_lock);
229  }
230  if (!tls_errbuf) {
231  return &SDL_global_errbuf;
232  }
233 
235  errbuf = (SDL_error *)SDL_TLSGet(tls_errbuf);
236  if (errbuf == ALLOCATION_IN_PROGRESS) {
237  return &SDL_global_errbuf;
238  }
239  if (!errbuf) {
240  /* Mark that we're in the middle of allocating our buffer */
241  SDL_TLSSet(tls_errbuf, ALLOCATION_IN_PROGRESS, NULL);
242  errbuf = (SDL_error *)SDL_malloc(sizeof(*errbuf));
243  if (!errbuf) {
244  SDL_TLSSet(tls_errbuf, NULL, NULL);
245  return &SDL_global_errbuf;
246  }
247  SDL_zerop(errbuf);
248  SDL_TLSSet(tls_errbuf, errbuf, SDL_free);
249  }
250  return errbuf;
251 }
int SDL_TLSSet(SDL_TLSID id, const void *value, void(*destructor)(void *))
Set the value associated with a thread local storage ID for the current thread.
Definition: SDL_thread.c:52
#define SDL_AtomicLock
#define SDL_MemoryBarrierRelease()
Definition: SDL_atomic.h:180
void * SDL_TLSGet(SDL_TLSID id)
Get the value associated with a thread local storage ID for the current thread.
Definition: SDL_thread.c:40
#define SDL_zerop(x)
Definition: SDL_stdinc.h:356
#define SDL_MemoryBarrierAcquire()
Definition: SDL_atomic.h:181
unsigned int SDL_TLSID
Definition: SDL_thread.h:52
#define SDL_AtomicUnlock
SDL_bool
Definition: SDL_stdinc.h:126
void SDL_free(void *mem)
#define NULL
Definition: begin_code.h:143
SDL_TLSID SDL_TLSCreate()
Create an identifier that is globally visible to all threads but refers to data that is thread-specif...
Definition: SDL_thread.c:33
#define SDL_malloc
int SDL_SpinLock
Definition: SDL_atomic.h:89