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"
61 SDL_THREAD_PRIORITY_NORMAL;
64 SDL_THREAD_PRIORITY_HIGH;
67 SDL_THREAD_PRIORITY_TIME_CRITICAL;
442 void Wait(
int* status);
506 return Thread(fn, std::move(name), data);
542 return Thread(std::move(fn), std::move(name));
642constexpr auto CREATE_ENTRY_FUNCTION_POINTER =
643 SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER;
645constexpr auto CREATE_NAME_STRING = SDL_PROP_THREAD_CREATE_NAME_STRING;
647constexpr auto CREATE_USERDATA_POINTER =
648 SDL_PROP_THREAD_CREATE_USERDATA_POINTER;
650constexpr auto CREATE_STACKSIZE_NUMBER =
651 SDL_PROP_THREAD_CREATE_STACKSIZE_NUMBER;
668 return SDL_GetThreadName(thread);
712 return SDL_GetThreadID(thread);
733 CheckError(SDL_SetCurrentThreadPriority(priority));
778 SDL_WaitThread(thread, status);
798 return SDL_GetThreadState(thread);
889 CheckError(SDL_SetTLS(
id, value, destructor));
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
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:199
ResourceRef< Properties > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:54
constexpr ThreadPriority THREAD_PRIORITY_HIGH
HIGH.
Definition SDL3pp_thread.h:63
void CleanupTLS()
Cleanup all TLS data for this thread.
Definition SDL3pp_thread.h:903
SDL_Thread * ThreadRaw
Alias to raw representation for Thread.
Definition SDL3pp_thread.h:36
Thread CreateThreadWithProperties(PropertiesRef props)
Create a new thread with with the specified properties.
Definition SDL3pp_thread.h:626
constexpr ThreadPriority THREAD_PRIORITY_TIME_CRITICAL
TIME_CRITICAL.
Definition SDL3pp_thread.h:66
constexpr ThreadState THREAD_DETACHED
The thread is detached and can't be waited on.
Definition SDL3pp_thread.h:86
ResourceRef< Thread > ThreadRef
Reference for Thread.
Definition SDL3pp_thread.h:43
const char * GetName() const
Get the thread name as it was specified in CreateThread().
Definition SDL3pp_thread.h:671
const char * GetThreadName(ThreadRef thread)
Get the thread name as it was specified in CreateThread().
Definition SDL3pp_thread.h:666
void DetachThread(ThreadRaw thread)
Let a thread clean up on exit without intervention.
Definition SDL3pp_thread.h:841
AtomicInt TLSID
Thread local storage ID.
Definition SDL3pp_thread.h:470
constexpr ThreadState THREAD_ALIVE
The thread is currently running.
Definition SDL3pp_thread.h:83
void WaitThread(ThreadRef thread, int *status)
Wait for a thread to finish.
Definition SDL3pp_thread.h:776
ThreadState GetThreadState(ThreadRef thread)
Get the current state of a thread.
Definition SDL3pp_thread.h:796
constexpr ThreadPriority THREAD_PRIORITY_LOW
LOW.
Definition SDL3pp_thread.h:58
SDL_ThreadID ThreadID
A unique numeric ID that identifies a thread.
Definition SDL3pp_thread.h:104
SDL_ThreadPriority ThreadPriority
The SDL thread priority.
Definition SDL3pp_thread.h:56
void SetCurrentThreadPriority(ThreadPriority priority)
Set the priority for the current thread.
Definition SDL3pp_thread.h:731
ThreadID GetCurrentThreadID()
Get the thread identifier for the current thread.
Definition SDL3pp_thread.h:691
constexpr ThreadState THREAD_UNKNOWN
The thread is not valid.
Definition SDL3pp_thread.h:80
void Detach()
Let a thread clean up on exit without intervention.
Definition SDL3pp_thread.h:843
static void SetCurrentPriority(ThreadPriority priority)
Set the priority for the current thread.
Definition SDL3pp_thread.h:736
SDL_ThreadState ThreadState
The SDL thread state.
Definition SDL3pp_thread.h:78
void Wait(int *status)
Wait for a thread to finish.
Definition SDL3pp_thread.h:781
Thread CreateThread(ThreadFunction fn, StringParam name, void *data)
Create a new thread with a default stack size.
Definition SDL3pp_thread.h:504
ThreadID GetID() const
Get the thread identifier for the specified thread.
Definition SDL3pp_thread.h:715
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:885
ThreadID GetThreadID(ThreadRef thread)
Get the thread identifier for the specified thread.
Definition SDL3pp_thread.h:710
constexpr ThreadPriority THREAD_PRIORITY_NORMAL
NORMAL.
Definition SDL3pp_thread.h:60
ThreadState GetState() const
Get the current state of a thread.
Definition SDL3pp_thread.h:801
constexpr ThreadState THREAD_COMPLETE
The thread has finished and should be cleaned up with Thread.Wait().
Definition SDL3pp_thread.h:90
std::function< int()> ThreadCB
The function passed to CreateThread() as the new thread's entry point.
Definition SDL3pp_thread.h:125
void * GetTLS(TLSID *id)
Get the current thread's value associated with a thread local storage ID.
Definition SDL3pp_thread.h:858
int(SDLCALL *)(void *data) ThreadFunction
The function passed to CreateThread() as the new thread's entry point.
Definition SDL3pp_thread.h:114
void(SDLCALL *)(void *value) TLSDestructorCallback
The callback used to cleanup data passed to SetTLS.
Definition SDL3pp_thread.h:138
Properties for CreateThreadWithProperties.
Definition SDL3pp_thread.h:640
Main include header for the SDL3pp library.
A type representing an atomic integer value.
Definition SDL3pp_atomic.h:218
Definition SDL3pp_callbackWrapper.h:20
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156
The SDL thread object.
Definition SDL3pp_thread.h:153
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr Thread & operator=(Thread &&other) noexcept
Assignment operator.
Definition SDL3pp_thread.h:318
constexpr Thread(ThreadRaw resource) noexcept
Constructs from raw Thread.
Definition SDL3pp_thread.h:163
~Thread()
Destructor.
Definition SDL3pp_thread.h:315
constexpr Thread(Thread &&other) noexcept
Move constructor.
Definition SDL3pp_thread.h:172
constexpr Thread(const Thread &other)=delete
Copy constructor.
Thread & operator=(const Thread &other)=delete
Assignment operator.