From 36e89dba4bbd19b0044e5e29080b016e899651b2 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 14 Apr 2025 23:47:35 +0200 Subject: [PATCH] cdrom: Support using C11 threads instead of libretro ones Libretro threads only work on... libretro. Add support for C11 threads for the non-libretro platforms that still want the async CD-ROM code. Signed-off-by: Paul Cercueil --- libpcsxcore/cdrom-async.c | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/libpcsxcore/cdrom-async.c b/libpcsxcore/cdrom-async.c index 76580965..71925522 100644 --- a/libpcsxcore/cdrom-async.c +++ b/libpcsxcore/cdrom-async.c @@ -41,7 +41,53 @@ static int rcdrom_isMediaInserted(void *stream) { return 0; } #endif +#ifdef USE_C11_THREADS +#include + +static int c11_threads_cb_wrapper(void *cb) +{ + ((void (*)(void *))cb)(NULL); + + return 0; +} + +#define slock_new() ({ \ + mtx_t *lock = malloc(sizeof(*lock)); \ + if (lock) mtx_init(lock, mtx_plain); \ + lock; \ +}) + +#define scond_new() ({ \ + cnd_t *cnd = malloc(sizeof(*cnd)); \ + if (cnd) cnd_init(cnd); \ + cnd; \ +}) + +#define pcsxr_sthread_create(cb, unused) ({ \ + thrd_t *thd = malloc(sizeof(*thd)); \ + if (thd) \ + thrd_create(thd, c11_threads_cb_wrapper, cb); \ + thd; \ +}) + +#define sthread_join(thrd) ({ \ + thrd_join(*thrd, NULL); \ + free(thrd); \ +}) + +#define slock_free(lock) free(lock) +#define slock_lock(lock) mtx_lock(lock) +#define slock_unlock(lock) mtx_unlock(lock) +#define scond_free(cond) free(cond) +#define scond_wait(cond, lock) cnd_wait(cond, lock) +#define scond_signal(cond) cnd_signal(cond) +#define slock_t mtx_t +#define scond_t cnd_t +#define sthread_t thrd_t +#else #include "../frontend/libretro-rthreads.h" +#endif + #include "retro_timers.h" struct cached_buf { -- 2.39.5