sdl3-bindgen-sys
Safe HaskellNone
LanguageGHC2021

SDL3.Sys.Bindgen.Thread.Safe

Synopsis

Documentation

sDL_CreateThreadRuntime Source #

Arguments

:: SDL_ThreadFunction
fn
the SDL_ThreadFunction function to call in the new thread
-> PtrConst CChar
name
the name of the thread
-> Ptr Void
data
a pointer that is passed to fn
-> SDL_FunctionPointer
pfnBeginThread
the C runtime's _beginthreadex (or whatnot). Can be NULL.
-> SDL_FunctionPointer
pfnEndThread
the C runtime's _endthreadex (or whatnot). Can be NULL.
-> IO (Ptr SDL_Thread) 

The actual entry point for SDL_CreateThread.

Returns
an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call SDL_GetError() for more information.
Thread safety
It is safe to call this function from any thread.
C declaration
SDL_CreateThreadRuntime, defined at SDL3/SDL_thread.h 340:42

Since: 3.2.0

sDL_CreateThreadWithPropertiesRuntime Source #

Arguments

:: SDL_PropertiesID
props
the properties to use
-> SDL_FunctionPointer
pfnBeginThread
the C runtime's _beginthreadex (or whatnot). Can be NULL.
-> SDL_FunctionPointer
pfnEndThread
the C runtime's _endthreadex (or whatnot). Can be NULL.
-> IO (Ptr SDL_Thread) 

The actual entry point for SDL_CreateThreadWithProperties.

Returns
an opaque pointer to the new thread object on success, NULL if the new thread could not be created; call SDL_GetError() for more information.
Thread safety
It is safe to call this function from any thread.
C declaration
SDL_CreateThreadWithPropertiesRuntime, defined at SDL3/SDL_thread.h 356:42

Since: 3.2.0

sDL_GetThreadName Source #

Arguments

:: Ptr SDL_Thread
thread
the thread to query.
-> IO (PtrConst CChar) 

Get the thread name as it was specified in SDL_CreateThread().

Returns
a pointer to a UTF-8 string that names the specified thread, or NULL if it doesn't have a name.
Thread safety
It is safe to call this function from any thread.
C declaration
SDL_GetThreadName, defined at SDL3/SDL_thread.h 378:42

Since: 3.2.0

sDL_GetCurrentThreadID :: IO SDL_ThreadID Source #

Get the thread identifier for the current thread.

This thread identifier is as reported by the underlying operating system. If SDL is running on a platform that does not support threads the return value will always be zero.

This function also returns a valid thread ID when called from the main thread.

Returns
the ID of the current thread.
Thread safety
It is safe to call this function from any thread.
See also
sDL_GetThreadID
C declaration
SDL_GetCurrentThreadID, defined at SDL3/SDL_thread.h 398:42

Since: 3.2.0

sDL_GetThreadID Source #

Arguments

:: Ptr SDL_Thread
thread
the thread to query.
-> IO SDL_ThreadID 

Get the thread identifier for the specified thread.

This thread identifier is as reported by the underlying operating system. If SDL is running on a platform that does not support threads the return value will always be zero.

Returns
the ID of the specified thread, or the ID of the current thread if thread is NULL.
Thread safety
It is safe to call this function from any thread.
See also
sDL_GetCurrentThreadID
C declaration
SDL_GetThreadID, defined at SDL3/SDL_thread.h 417:42

Since: 3.2.0

sDL_SetCurrentThreadPriority Source #

Arguments

:: SDL_ThreadPriority
priority
the SDL_ThreadPriority to set.
-> IO CBool 

Set the priority for the current thread.

Note that some platforms will not let you alter the priority (or at least, promote the thread to a higher priority) at all, and some require you to be an administrator account. Be prepared for this to fail.

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.
C declaration
SDL_SetCurrentThreadPriority, defined at SDL3/SDL_thread.h 434:34

Since: 3.2.0

sDL_WaitThread Source #

Arguments

:: Ptr SDL_Thread
thread
the SDL_Thread pointer that was returned from the SDL_CreateThread() call that started this thread.
-> Ptr CInt
status
a pointer filled in with the value returned from the thread function by its 'return', or -1 if the thread has been detached or isn't valid, may be NULL.
-> IO () 

Wait for a thread to finish.

Threads that haven't been detached will remain until this function cleans them up. Not doing so is a resource leak.

Once a thread has been cleaned up through this function, the SDL_Thread that references it becomes invalid and should not be referenced again. As such, only one thread may call SDL_WaitThread() on another.

The return code from the thread function is placed in the area pointed to by status, if status is not NULL.

You may not wait on a thread that has been used in a call to SDL_DetachThread(). Use either that function or this one, but not both, or behavior is undefined.

It is safe to pass a NULL thread to this function; it is a no-op.

Note that the thread pointer is freed by this function and is not valid afterward.

Thread safety
It is safe to call this function from any thread, but only a single thread can wait any specific thread to finish.
See also
SDL_CreateThread, sDL_DetachThread
C declaration
SDL_WaitThread, defined at SDL3/SDL_thread.h 472:34

Since: 3.2.0

sDL_GetThreadState Source #

Arguments

:: Ptr SDL_Thread
thread
the thread to query.
-> IO SDL_ThreadState 

Get the current state of a thread.

Returns
the current state of a thread, or SDL_THREAD_UNKNOWN if the thread isn't valid.
Thread safety
It is safe to call this function from any thread.
See also
SDL_ThreadState
C declaration
SDL_GetThreadState, defined at SDL3/SDL_thread.h 487:45

Since: 3.2.0

sDL_DetachThread Source #

Arguments

:: Ptr SDL_Thread
thread
the SDL_Thread pointer that was returned from the SDL_CreateThread() call that started this thread.
-> IO () 

Let a thread clean up on exit without intervention.

A thread may be "detached" to signify that it should not remain until another thread has called SDL_WaitThread() on it. Detaching a thread is useful for long-running threads that nothing needs to synchronize with or further manage. When a detached thread is done, it simply goes away.

There is no way to recover the return code of a detached thread. If you need this, don't detach the thread and instead use SDL_WaitThread().

Once a thread is detached, you should usually assume the SDL_Thread isn't safe to reference again, as it will become invalid immediately upon the detached thread's exit, instead of remaining until someone has called SDL_WaitThread() to finally clean it up. As such, don't detach the same thread more than once.

If a thread has already exited when passed to SDL_DetachThread(), it will stop waiting for a call to SDL_WaitThread() and clean up immediately. It is not safe to detach a thread that might be used with SDL_WaitThread().

You may not call SDL_WaitThread() on a thread that has been detached. Use either that function or this one, but not both, or behavior is undefined.

It is safe to pass NULL to this function; it is a no-op.

Thread safety
It is safe to call this function from any thread.
See also
SDL_CreateThread, sDL_WaitThread
C declaration
SDL_DetachThread, defined at SDL3/SDL_thread.h 525:34

Since: 3.2.0

sDL_GetTLS Source #

Arguments

:: Ptr SDL_TLSID
id
a pointer to the thread local storage ID, may not be NULL.
-> IO (Ptr Void) 

Get the current thread's value associated with a thread local storage ID.

Returns
the value associated with the ID for the current thread or NULL if no value has been set; call SDL_GetError() for more information.
Thread safety
It is safe to call this function from any thread.
See also
sDL_SetTLS
C declaration
SDL_GetTLS, defined at SDL3/SDL_thread.h 540:36

Since: 3.2.0

sDL_SetTLS Source #

Arguments

:: Ptr SDL_TLSID
id
a pointer to the thread local storage ID, may not be NULL.
-> PtrConst Void
value
the value to associate with the ID for the current thread.
-> SDL_TLSDestructorCallback
destructor
a function called when the thread exits, to free the value, may be NULL.
-> IO CBool 

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.

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.
See also
sDL_GetTLS
C declaration
SDL_SetTLS, defined at SDL3/SDL_thread.h 581:34

Since: 3.2.0

sDL_CleanupTLS :: IO () Source #

Cleanup all TLS data for this thread.

If you are creating your threads outside of SDL and then calling SDL functions, you should call this function before your thread exits, to properly clean up SDL memory.

Thread safety
It is safe to call this function from any thread.
C declaration
SDL_CleanupTLS, defined at SDL3/SDL_thread.h 594:34

Since: 3.2.0