diff --git a/bootstrap/vita/threading.c b/bootstrap/vita/threading.c index 1aab2bfa7a..cceca6b30a 100644 --- a/bootstrap/vita/threading.c +++ b/bootstrap/vita/threading.c @@ -33,7 +33,13 @@ int __vita_delete_thread_reent(int thid) // We only need to cleanup if reent is allocated, i.e. if it's on our TLS // We also don't need to clean up the global reent - struct _reent **on_tls = TLS_REENT_THID_PTR(thid); + struct _reent **on_tls = NULL; + + if (thid == 0) + on_tls = TLS_REENT_PTR; + else + on_tls = TLS_REENT_THID_PTR(thid); + if (!*on_tls || *on_tls == &_newlib_global_reent) return 0; @@ -71,7 +77,7 @@ int _exit_thread_common(int exit_status, int (*exit_func)(int)) { // Lock the list because we'll be modifying it sceKernelLockMutex(_newlib_reent_mutex, 1, NULL); - res = __vita_delete_thread_reent(thid); + res = __vita_delete_thread_reent(0); ret = exit_func(exit_status); @@ -145,7 +151,7 @@ struct _reent *__getreent_for_thread(int thid) { return *on_tls; } - sceKernelLockMutex(_newlib_reent_mutex, 1, 0); + sceKernelLockMutex(_newlib_reent_mutex, 1, 0); // If it's not on the TLS this means the thread doesn't have a reent allocated yet // We allocate one and put a pointer to it on the TLS @@ -171,6 +177,9 @@ struct _reent *__getreent_for_thread(int thid) { memset(free_reent, 0, sizeof(struct reent_for_thread)); // Set it up + if(thid==0){ + thid = sceKernelGetThreadId(); + } free_reent->thread_id = thid; _REENT_INIT_PTR(&free_reent->reent); returned_reent = &free_reent->reent;