mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-16 09:48:26 +00:00
Cleaned up thread state handling and added thread object validation
This commit is contained in:
parent
7647f16ae1
commit
eb1be89e70
6 changed files with 54 additions and 34 deletions
|
@ -105,8 +105,7 @@ typedef enum SDL_ThreadPriority {
|
|||
/**
|
||||
* The SDL thread state.
|
||||
*
|
||||
* SDL stores the current state of a thread in an atomic int. The current
|
||||
* state of a thread can be checked by calling SDL_GetThreadState.
|
||||
* The current state of a thread can be checked by calling SDL_GetThreadState.
|
||||
*
|
||||
* \since This enum is available since SDL 3.1.3.
|
||||
*
|
||||
|
@ -114,10 +113,10 @@ typedef enum SDL_ThreadPriority {
|
|||
*/
|
||||
typedef enum SDL_ThreadState
|
||||
{
|
||||
SDL_THREAD_STATE_ALIVE,
|
||||
SDL_THREAD_STATE_DETACHED,
|
||||
SDL_THREAD_STATE_ZOMBIE,
|
||||
SDL_THREAD_STATE_CLEANED,
|
||||
SDL_THREAD_UNKNOWN, /**< The thread is not valid */
|
||||
SDL_THREAD_ALIVE, /**< The thread is currently running */
|
||||
SDL_THREAD_DETACHED, /**< The thread is detached and can't be waited on */
|
||||
SDL_THREAD_COMPLETE, /**< The thread has finished and should be cleaned up with SDL_WaitThread() */
|
||||
} SDL_ThreadState;
|
||||
|
||||
/**
|
||||
|
@ -408,14 +407,14 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetCurrentThreadPriority(SDL_ThreadPriority
|
|||
/**
|
||||
* Wait for a thread to finish.
|
||||
*
|
||||
* Threads that haven't been detached will remain (as a "zombie") until this
|
||||
* 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 for the thread function is placed in the area pointed to by
|
||||
* 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
|
||||
|
@ -429,9 +428,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetCurrentThreadPriority(SDL_ThreadPriority
|
|||
*
|
||||
* \param thread the SDL_Thread pointer that was returned from the
|
||||
* SDL_CreateThread() call that started this thread.
|
||||
* \param status pointer to an integer that will receive the value returned
|
||||
* from the thread function by its 'return', or NULL to not
|
||||
* receive such value back.
|
||||
* \param 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.
|
||||
*
|
||||
* \since This function is available since SDL 3.1.3.
|
||||
*
|
||||
|
@ -443,9 +441,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
|
|||
/**
|
||||
* Get the current state of a thread.
|
||||
*
|
||||
* \param thread the thread whose status you want to check.
|
||||
* \returns the current state of a thread as defined in the SDL_ThreadState
|
||||
* enum.
|
||||
* \param thread the thread to query.
|
||||
* \returns the current state of a thread, or SDL_THREAD_UNKNOWN if the thread isn't valid.
|
||||
*
|
||||
* \since This function is available since SDL 3.2.0.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue