mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-04 08:56:25 +00:00
Remove the reference to the thread when it is detached
Fixes https://github.com/libsdl-org/SDL/issues/12301
This commit is contained in:
@@ -334,7 +334,6 @@ void SDL_RunThread(SDL_Thread *thread)
|
||||
if (!SDL_CompareAndSwapAtomicInt(&thread->state, SDL_THREAD_ALIVE, SDL_THREAD_COMPLETE)) {
|
||||
// Clean up if something already detached us.
|
||||
if (SDL_GetThreadState(thread) == SDL_THREAD_DETACHED) {
|
||||
SDL_SetObjectValid(thread, SDL_OBJECT_TYPE_THREAD, false);
|
||||
SDL_free(thread->name); // Can't free later, we've already cleaned up TLS
|
||||
SDL_free(thread);
|
||||
}
|
||||
@@ -457,7 +456,7 @@ bool SDL_SetCurrentThreadPriority(SDL_ThreadPriority priority)
|
||||
|
||||
void SDL_WaitThread(SDL_Thread *thread, int *status)
|
||||
{
|
||||
if (!ThreadValid(thread) || SDL_GetThreadState(thread) == SDL_THREAD_DETACHED) {
|
||||
if (!ThreadValid(thread)) {
|
||||
if (status) {
|
||||
*status = -1;
|
||||
}
|
||||
@@ -488,6 +487,9 @@ void SDL_DetachThread(SDL_Thread *thread)
|
||||
return;
|
||||
}
|
||||
|
||||
// The thread may vanish at any time, it's no longer valid
|
||||
SDL_SetObjectValid(thread, SDL_OBJECT_TYPE_THREAD, false);
|
||||
|
||||
// Grab dibs if the state is alive+joinable.
|
||||
if (SDL_CompareAndSwapAtomicInt(&thread->state, SDL_THREAD_ALIVE, SDL_THREAD_DETACHED)) {
|
||||
SDL_SYS_DetachThread(thread);
|
||||
|
Reference in New Issue
Block a user