1#ifndef SDL3PP_THREAD_H_
2#define SDL3PP_THREAD_H_
4#include <SDL3/SDL_thread.h>
5#include "SDL3pp_atomic.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
139 SDL_THREAD_PRIORITY_NORMAL;
142 SDL_THREAD_PRIORITY_HIGH;
145 SDL_THREAD_PRIORITY_TIME_CRITICAL;
197 const char*
GetName()
const {
return SDL_GetThreadName(
get()); }
229 CheckError(SDL_SetCurrentThreadPriority(priority));
263 void Wait(
int* status) { SDL_WaitThread(
get(), status); }
311 static void reset(SDL_Thread* resource) { SDL_DetachThread(resource); }
510namespace prop::thread {
512constexpr auto CREATE_ENTRY_FUNCTION_POINTER =
513 SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER;
515constexpr auto CREATE_NAME_STRING = SDL_PROP_THREAD_CREATE_NAME_STRING;
517constexpr auto CREATE_USERDATA_POINTER =
518 SDL_PROP_THREAD_CREATE_USERDATA_POINTER;
520constexpr auto CREATE_STACKSIZE_NUMBER =
521 SDL_PROP_THREAD_CREATE_STACKSIZE_NUMBER;
587 CheckError(SDL_SetTLS(*
id, value, destructor));
A type representing an atomic integer value.
Definition SDL3pp_atomic.h:210
RESOURCE release()
Returns reference and reset this.
Definition SDL3pp_resource.h:178
Implement shared ownership for a resource.
Definition SDL3pp_resource.h:283
Implement unique ownership for a resource.
Definition SDL3pp_resource.h:226
constexpr ResourceUnique(std::nullptr_t=nullptr)
Default constructor.
Definition SDL3pp_resource.h:231
void reset()
Resets the value, destroying the resource if not nullptr.
Definition SDL3pp_resource.h:265
A dumb pointer to resource.
Definition SDL3pp_resource.h:197
constexpr ResourceUnsafe()=default
Default constructor.
Implement weak ownership for a resource.
Definition SDL3pp_resource.h:328
A SDL managed resource.
Definition SDL3pp_resource.h:29
constexpr Resource(T resource={})
Constructs from the underlying resource.
Definition SDL3pp_resource.h:37
constexpr SDL_Thread * get() const
Return contained resource;.
Definition SDL3pp_resource.h:76
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
constexpr ThreadPriority THREAD_PRIORITY_HIGH
HIGH.
Definition SDL3pp_thread.h:141
void CleanupTLS()
Cleanup all TLS data for this thread.
Definition SDL3pp_thread.h:601
constexpr ThreadPriority THREAD_PRIORITY_TIME_CRITICAL
TIME_CRITICAL.
Definition SDL3pp_thread.h:144
constexpr ThreadState THREAD_DETACHED
The thread is detached and can't be waited on.
Definition SDL3pp_thread.h:164
SDL_TLSDestructorCallback TLSDestructorCallback
The callback used to cleanup data passed to SetTLS.
Definition SDL3pp_thread.h:95
constexpr ThreadState THREAD_ALIVE
The thread is currently running.
Definition SDL3pp_thread.h:161
constexpr ThreadPriority THREAD_PRIORITY_LOW
LOW.
Definition SDL3pp_thread.h:136
SDL_ThreadState ThreadState
The SDL thread state.
Definition SDL3pp_thread.h:156
std::function< int()> ThreadCB
The function passed to Thread.Create() as the new thread's entry point.
Definition SDL3pp_thread.h:82
ThreadID GetCurrentThreadID()
Get the thread identifier for the current thread.
Definition SDL3pp_thread.h:541
constexpr ThreadState THREAD_UNKNOWN
The thread is not valid.
Definition SDL3pp_thread.h:158
SDL_ThreadPriority ThreadPriority
The SDL thread priority.
Definition SDL3pp_thread.h:134
SDL_ThreadID ThreadID
A unique numeric ID that identifies a thread.
Definition SDL3pp_thread.h:49
void SetTLS(TLSID *id, const void *value, TLSDestructorCallback destructor)
Set the current thread's value associated with a thread local storage ID.
Definition SDL3pp_thread.h:583
ThreadShared share()
Move this thread into a ThreadShared.
Definition SDL3pp_thread.h:483
constexpr ThreadPriority THREAD_PRIORITY_NORMAL
NORMAL.
Definition SDL3pp_thread.h:138
constexpr ThreadState THREAD_COMPLETE
The thread has finished and should be cleaned up with ThreadRef.Wait()
Definition SDL3pp_thread.h:170
ResourceShared< Thread > ThreadShared
Handle to a shared thread.
Definition SDL3pp_thread.h:111
SDL_ThreadFunction ThreadFunction
The function passed to Thread.Create() as the new thread's entry point.
Definition SDL3pp_thread.h:72
void * GetTLS(TLSID *id)
Get the current thread's value associated with a thread local storage ID.
Definition SDL3pp_thread.h:556
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
Definition SDL3pp_callbackWrapper.h:66
SDL properties ID.
Definition SDL3pp_properties.h:209
The SDL thread object.
Definition SDL3pp_thread.h:186
ThreadState GetState() const
Get the current state of a thread.
Definition SDL3pp_thread.h:275
void Wait(int *status)
Wait for a thread to finish.
Definition SDL3pp_thread.h:263
const char * GetName() const
Get the thread name as it was specified in (Thread.Create).
Definition SDL3pp_thread.h:197
static void SetCurrentPriority(ThreadPriority priority)
Set the priority for the current thread.
Definition SDL3pp_thread.h:227
ThreadID GetID() const
Get the thread identifier for the specified thread.
Definition SDL3pp_thread.h:213
static void reset(SDL_Thread *resource)
Let a thread clean up on exit without intervention.
Definition SDL3pp_thread.h:311
Unsafe Handle to thread.
Definition SDL3pp_thread.h:498
constexpr ThreadUnsafe(Thread &&other)
Constructs ThreadUnsafe from Thread.
Definition SDL3pp_thread.h:504
Handle to an owned thread.
Definition SDL3pp_thread.h:322
static Thread Create(ThreadCB fn, StringParam name)
Create a new thread with a default stack size.
Definition SDL3pp_thread.h:338
static Thread Create(ThreadFunction fn, StringParam name, void *data)
Create a new thread with a default stack size.
Definition SDL3pp_thread.h:372
void Detach()
Let a thread clean up on exit without intervention.
Definition SDL3pp_thread.h:474
static Thread CreateWithProperties(PropertiesRef props)
Create a new thread with with the specified properties.
Definition SDL3pp_thread.h:440