Skip to content

Commit

Permalink
Hopefully fix the segfaults in retro_deinit
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG committed Sep 24, 2023
1 parent dc16632 commit 260b716
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/libretro/platform/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
#include <Platform.h>

#include <utility>
#include <retro_timers.h>

using Platform::Thread;
struct Platform::Thread {
sthread_t *thread;
bool joined;
};
struct ThreadData {
std::function<void()> fn;
};
Expand All @@ -34,20 +37,28 @@ static void function_trampoline(void *param) {

Thread *Platform::Thread_Create(std::function<void()> func) {
#if HAVE_THREADS
return (Thread *) sthread_create(function_trampoline, new ThreadData{std::move(func)});
return new Thread {
sthread_create(function_trampoline, new ThreadData{std::move(func)}),
false
};
#else
return nullptr;
#endif
}

void Platform::Thread_Free(Thread *thread) {
void Platform::Thread_Wait(Thread *thread) {
#if HAVE_THREADS
sthread_detach((sthread_t *) thread);
sthread_join(thread->thread);
thread->joined = true;
#endif
}

void Platform::Thread_Wait(Thread *thread) {
void Platform::Thread_Free(Thread *thread) {
#if HAVE_THREADS
sthread_join((sthread_t *) thread);
if (!thread->joined)
sthread_detach(thread->thread);

thread->thread = nullptr;
delete thread;
#endif
}

0 comments on commit 260b716

Please sign in to comment.