From: notaz Date: Fri, 19 Dec 2025 20:04:14 +0000 (+0200) Subject: cdrom-async: move thread stuff out X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6112127e647160ac9a30999752c4c46228b757a4;p=pcsx_rearmed.git cdrom-async: move thread stuff out --- diff --git a/Makefile b/Makefile index 92c43018..9df61c85 100644 --- a/Makefile +++ b/Makefile @@ -453,7 +453,7 @@ INC_LIBRETRO_COMMON := 1 endif # $(PLATFORM) == "libretro" ifeq "$(USE_RTHREADS)" "1" -OBJS += frontend/libretro-rthreads.o +OBJS += frontend/pcsxr-threads.o OBJS += deps/libretro-common/features/features_cpu.o frontend/main.o: CFLAGS += -DHAVE_RTHREADS INC_LIBRETRO_COMMON := 1 diff --git a/frontend/libretro-rthreads.h b/frontend/libretro-rthreads.h deleted file mode 100644 index 6a2d004b..00000000 --- a/frontend/libretro-rthreads.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __LIBRETRO_PCSXR_RTHREADS_H__ -#define __LIBRETRO_PCSXR_RTHREADS_H__ - -#include "rthreads/rthreads.h" - -enum pcsxr_thread_type -{ - PCSXRT_CDR = 0, - PCSXRT_DRC, - PCSXRT_GPU, - PCSXRT_SPU, - PCSXRT_COUNT // must be last -}; - -void pcsxr_sthread_init(void); -sthread_t *pcsxr_sthread_create(void (*thread_func)(void*), - enum pcsxr_thread_type type); - -#endif // __LIBRETRO_PCSXR_RTHREADS_H__ diff --git a/frontend/main.c b/frontend/main.c index debfb11b..751c4520 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -15,7 +15,7 @@ #include #endif #ifdef HAVE_RTHREADS -#include "../frontend/libretro-rthreads.h" +#include "../frontend/pcsxr-threads.h" #endif #include "main.h" diff --git a/frontend/libretro-rthreads.c b/frontend/pcsxr-threads.c similarity index 98% rename from frontend/libretro-rthreads.c rename to frontend/pcsxr-threads.c index 90067b13..1c1ff2e6 100644 --- a/frontend/libretro-rthreads.c +++ b/frontend/pcsxr-threads.c @@ -10,7 +10,7 @@ #include "../deps/libretro-common/rthreads/rthreads.c" #include "features/features_cpu.h" -#include "libretro-rthreads.h" +#include "pcsxr-threads.h" // pcsxr "extensions" extern void SysPrintf(const char *fmt, ...); diff --git a/frontend/pcsxr-threads.h b/frontend/pcsxr-threads.h new file mode 100644 index 00000000..977830e0 --- /dev/null +++ b/frontend/pcsxr-threads.h @@ -0,0 +1,73 @@ +#ifndef __PCSXR_THREADS_H__ +#define __PCSXR_THREADS_H__ + +enum pcsxr_thread_type +{ + PCSXRT_CDR = 0, + PCSXRT_DRC, + PCSXRT_GPU, + PCSXRT_SPU, + PCSXRT_COUNT // must be last +}; + +#ifndef USE_C11_THREADS + +/* use libretro-common rthreads */ +#include "rthreads/rthreads.h" + +#define STRHEAD_RET_TYPE void +#define STRHEAD_RETURN() + +void pcsxr_sthread_init(void); +sthread_t *pcsxr_sthread_create(void (*thread_func)(void*), + enum pcsxr_thread_type type); + +#else + +/* C11 concurrency support */ +#include + +#define STRHEAD_RET_TYPE int +#define STRHEAD_RETURN() return 0 + +#define pcsxr_sthread_init() + +#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, cb, NULL); \ + thd; \ +}) + +#define sthread_join(thrd) { \ + if (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 + +#endif // USE_C11_THREADS + +#endif // __PCSXR_THREADS_H__ diff --git a/jni/Android.mk b/jni/Android.mk index 81c2e120..5d132d68 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -239,7 +239,7 @@ USE_RTHREADS := 1 endif ifeq ($(USE_RTHREADS),1) SOURCES_C += \ - $(FRONTEND_DIR)/libretro-rthreads.c \ + $(FRONTEND_DIR)/pcsxr-threads.c \ $(LIBRETRO_COMMON)/features/features_cpu.c COREFLAGS += -DHAVE_RTHREADS endif diff --git a/libpcsxcore/cdrom-async.c b/libpcsxcore/cdrom-async.c index 9df31150..e52b648d 100644 --- a/libpcsxcore/cdrom-async.c +++ b/libpcsxcore/cdrom-async.c @@ -42,53 +42,7 @@ 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 "../frontend/pcsxr-threads.h" #ifdef HAVE_LIBRETRO #include "retro_timers.h" #endif @@ -179,7 +133,7 @@ static int lbacache_get(unsigned int lba, void *buf, void *sub_buf) // note: This has races on some vars but that's ok, main thread can deal // with it. Only unsafe buffer accesses and simultaneous reads are prevented. -static void cdra_prefetch_thread(void *unused) +static STRHEAD_RET_TYPE cdra_prefetch_thread(void *unused) { u32 buf_cnt, lba, lba_to; @@ -214,6 +168,7 @@ static void cdra_prefetch_thread(void *unused) slock_lock(acdrom.buf_lock); } slock_unlock(acdrom.buf_lock); + STRHEAD_RETURN(); } void cdra_stop_thread(void) diff --git a/libpcsxcore/new_dynarec/emu_if.c b/libpcsxcore/new_dynarec/emu_if.c index cefadd21..d88e147a 100644 --- a/libpcsxcore/new_dynarec/emu_if.c +++ b/libpcsxcore/new_dynarec/emu_if.c @@ -22,7 +22,7 @@ #define FLAGLESS #include "../gte.h" #if defined(NDRC_THREAD) && !defined(DRC_DISABLE) && !defined(LIGHTREC) -#include "../../frontend/libretro-rthreads.h" +#include "../../frontend/pcsxr-threads.h" #include "features/features_cpu.h" #include "retro_timers.h" #endif @@ -487,7 +487,7 @@ static int ari64_thread_check_range(unsigned int start, unsigned int end) return 1; } -static void ari64_compile_thread(void *unused) +static STRHEAD_RET_TYPE ari64_compile_thread(void *unused) { struct ht_entry *hash_table = *(void **)((char *)dynarec_local + LO_hash_table_ptr); @@ -511,6 +511,7 @@ static void ari64_compile_thread(void *unused) } slock_unlock(ndrc_g.thread.lock); (void)target; + STRHEAD_RETURN(); } static void ari64_thread_shutdown(void)