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

◆ ERR_MAX_ARGS

#define ERR_MAX_ARGS   5

Definition at line 32 of file SDL_error_c.h.

◆ ERR_MAX_STRLEN

#define ERR_MAX_STRLEN   128

Definition at line 31 of file SDL_error_c.h.

Function Documentation

◆ SDL_GetErrBuf()

SDL_error* SDL_GetErrBuf ( void  )

Definition at line 206 of file SDL_thread.c.

207 {
208 #if SDL_THREADS_DISABLED
209  /* Non-thread-safe global error variable */
210  static SDL_error SDL_global_error;
211  return &SDL_global_error;
212 #else
213  static SDL_SpinLock tls_lock;
214  static SDL_bool tls_being_created;
215  static SDL_TLSID tls_errbuf;
216  static SDL_error SDL_global_errbuf;
217  const SDL_error *ALLOCATION_IN_PROGRESS = (SDL_error *)-1;
218  SDL_error *errbuf;
219 
220  /* tls_being_created is there simply to prevent recursion if SDL_TLSCreate() fails.
221  It also means it's possible for another thread to also use SDL_global_errbuf,
222  but that's very unlikely and hopefully won't cause issues.
223  */
224  if (!tls_errbuf && !tls_being_created) {
225  SDL_AtomicLock(&tls_lock);
226  if (!tls_errbuf) {
227  SDL_TLSID slot;
228  tls_being_created = SDL_TRUE;
229  slot = SDL_TLSCreate();
230  tls_being_created = SDL_FALSE;
232  tls_errbuf = slot;
233  }
234  SDL_AtomicUnlock(&tls_lock);
235  }
236  if (!tls_errbuf) {
237  return &SDL_global_errbuf;
238  }
239 
241  errbuf = (SDL_error *)SDL_TLSGet(tls_errbuf);
242  if (errbuf == ALLOCATION_IN_PROGRESS) {
243  return &SDL_global_errbuf;
244  }
245  if (!errbuf) {
246  /* Mark that we're in the middle of allocating our buffer */
247  SDL_TLSSet(tls_errbuf, ALLOCATION_IN_PROGRESS, NULL);
248  errbuf = (SDL_error *)SDL_malloc(sizeof(*errbuf));
249  if (!errbuf) {
250  SDL_TLSSet(tls_errbuf, NULL, NULL);
251  return &SDL_global_errbuf;
252  }
253  SDL_zerop(errbuf);
254  SDL_TLSSet(tls_errbuf, errbuf, SDL_free);
255  }
256  return errbuf;
257 #endif /* SDL_THREADS_DISABLED */
258 }

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.

Referenced by SDL_ClearError(), SDL_GetErrorMsg(), and SDL_SetError().

NULL
#define NULL
Definition: begin_code.h:167
SDL_MemoryBarrierRelease
#define SDL_MemoryBarrierRelease()
Definition: SDL_atomic.h:207
SDL_zerop
#define SDL_zerop(x)
Definition: SDL_stdinc.h:419
SDL_AtomicLock
#define SDL_AtomicLock
Definition: SDL_dynapi_overrides.h:64
SDL_error
Definition: SDL_error_c.h:34
SDL_AtomicUnlock
#define SDL_AtomicUnlock
Definition: SDL_dynapi_overrides.h:65
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_TLSID
unsigned int SDL_TLSID
Definition: SDL_thread.h:52
SDL_TLSCreate
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:34
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_SpinLock
int SDL_SpinLock
Definition: SDL_atomic.h:89
SDL_MemoryBarrierAcquire
#define SDL_MemoryBarrierAcquire()
Definition: SDL_atomic.h:208
SDL_TLSGet
void * SDL_TLSGet(SDL_TLSID id)
Get the value associated with a thread local storage ID for the current thread.
Definition: SDL_thread.c:41
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_TLSSet
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:53