Fix thread detachment on Vita

This commit is contained in:
Cameron Gutman 2024-02-17 18:14:49 -06:00
parent 9686f6942f
commit 59f7f62b62
2 changed files with 12 additions and 4 deletions

View File

@ -88,7 +88,13 @@ void* ThreadProc(void* context) {
ctx->entry(ctx->context); ctx->entry(ctx->context);
#if defined(__vita__) #if defined(__vita__)
ctx->thread->alive = false; if (ctx->thread->detached) {
free(ctx);
sceKernelExitDeleteThread(0);
}
else {
free(ctx);
}
#else #else
free(ctx); free(ctx);
#endif #endif
@ -192,6 +198,7 @@ void PltJoinThread(PLT_THREAD* thread) {
WaitForSingleObjectEx(thread->handle, INFINITE, FALSE); WaitForSingleObjectEx(thread->handle, INFINITE, FALSE);
CloseHandle(thread->handle); CloseHandle(thread->handle);
#elif defined(__vita__) #elif defined(__vita__)
LC_ASSERT(!thread->detached);
sceKernelWaitThreadEnd(thread->handle, NULL, NULL); sceKernelWaitThreadEnd(thread->handle, NULL, NULL);
sceKernelDeleteThread(thread->handle); sceKernelDeleteThread(thread->handle);
#elif defined(__WIIU__) #elif defined(__WIIU__)
@ -213,7 +220,8 @@ void PltDetachThread(PLT_THREAD* thread) {
// "Closing a thread handle does not terminate the associated thread or remove the thread object." // "Closing a thread handle does not terminate the associated thread or remove the thread object."
CloseHandle(thread->handle); CloseHandle(thread->handle);
#elif defined(__vita__) #elif defined(__vita__)
sceKernelDeleteThread(thread->handle); LC_ASSERT(!thread->detached);
thread->detached = true;
#elif defined(__WIIU__) #elif defined(__WIIU__)
OSDetachThread(&thread->thread); OSDetachThread(&thread->thread);
#elif defined(__3DS__) #elif defined(__3DS__)
@ -261,7 +269,7 @@ int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THRE
} }
#elif defined(__vita__) #elif defined(__vita__)
{ {
thread->alive = true; thread->detached = false;
thread->context = ctx; thread->context = ctx;
ctx->thread = thread; ctx->thread = thread;
thread->handle = sceKernelCreateThread(name, ThreadProc, 0, 0x40000, 0, 0, NULL); thread->handle = sceKernelCreateThread(name, ThreadProc, 0, 0x40000, 0, 0, NULL);

View File

@ -19,7 +19,7 @@ typedef struct _PLT_THREAD {
int handle; int handle;
int cancelled; int cancelled;
void *context; void *context;
bool alive; bool detached;
} PLT_THREAD; } PLT_THREAD;
#elif defined(__WIIU__) #elif defined(__WIIU__)
typedef OSFastMutex PLT_MUTEX; typedef OSFastMutex PLT_MUTEX;