Use atomics for thread cancellation

This commit is contained in:
Cameron Gutman committed 2026-11-10 23:34:03 -06:00
1 parent 7d884fadc3
commit c3360b7102
2 files changed
+8 -6

No files matched your search

+2 -2
View File
@@ -211,11 +211,11 @@ void PltDetachThread(PLT_THREAD* thread) {
}
bool PltIsThreadInterrupted(PLT_THREAD* thread) {
return thread->cancelled;
return atomic_load_explicit(&thread->cancelled, memory_order_acquire);
}
void PltInterruptThread(PLT_THREAD* thread) {
thread->cancelled = true;
atomic_store_explicit(&thread->cancelled, true, memory_order_release);
}
#ifdef __WIIU__
+6 -4
View File
@@ -3,6 +3,8 @@
#include "Limelight.h"
#include "Platform.h"
#include <stdatomic.h>
typedef void(*ThreadEntry)(void* context);
#if defined(LC_WINDOWS)
@@ -10,28 +12,28 @@ typedef SRWLOCK PLT_MUTEX;
typedef CONDITION_VARIABLE PLT_COND;
typedef struct _PLT_THREAD {
HANDLE handle;
bool cancelled;
atomic_bool cancelled;
} PLT_THREAD;
#elif defined(__WIIU__)
typedef OSFastMutex PLT_MUTEX;
typedef OSFastCondition PLT_COND;
typedef struct _PLT_THREAD {
OSThread thread;
int cancelled;
atomic_bool cancelled;
} PLT_THREAD;
#elif defined(__3DS__)
typedef LightLock PLT_MUTEX;
typedef CondVar PLT_COND;
typedef struct _PLT_THREAD {
Thread thread;
bool cancelled;
atomic_bool cancelled;
} PLT_THREAD;
#elif defined (LC_POSIX)
typedef pthread_mutex_t PLT_MUTEX;
typedef pthread_cond_t PLT_COND;
typedef struct _PLT_THREAD {
pthread_t thread;
bool cancelled;
atomic_bool cancelled;
} PLT_THREAD;
#else
#error Unsupported platform