Function SDL_SetTLS

pub unsafe extern "C" fn SDL_SetTLS(
    id: *mut SDL_AtomicInt,
    value: *const c_void,
    destructor: Option<unsafe extern "C" fn(_: *mut c_void)>,
) -> bool
Available on crate feature dep_sdl3 only.
Expand description

Set the current thread’s value associated with a thread local storage ID.

If the thread local storage ID is not initialized (the value is 0), a new ID will be created in a thread-safe way, so all calls using a pointer to the same ID will refer to the same local storage.

Note that replacing a value from a previous call to this function on the same thread does not call the previous value’s destructor!

destructor can be NULL; it is assumed that value does not need to be cleaned up if so.

§Parameters

  • id: a pointer to the thread local storage ID, may not be NULL.
  • value: the value to associate with the ID for the current thread.
  • destructor: a function called when the thread exits, to free the value, may be NULL.

§Return value

Returns true on success or false on failure; call SDL_GetError() for more information.

§Thread safety

It is safe to call this function from any thread.

§Availability

This function is available since SDL 3.2.0.

§See also