cdrom-async: move thread stuff out
authornotaz <notasas@gmail.com>
Fri, 19 Dec 2025 20:04:14 +0000 (22:04 +0200)
committernotaz <notasas@gmail.com>
Fri, 19 Dec 2025 20:04:14 +0000 (22:04 +0200)
Makefile
frontend/libretro-rthreads.h [deleted file]
frontend/main.c
frontend/pcsxr-threads.c [moved from frontend/libretro-rthreads.c with 98% similarity]
frontend/pcsxr-threads.h [new file with mode: 0644]
jni/Android.mk
libpcsxcore/cdrom-async.c
libpcsxcore/new_dynarec/emu_if.c

index 92c4301..9df61c8 100644 (file)
--- 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 (file)
index 6a2d004..0000000
+++ /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__
index debfb11..751c452 100644 (file)
@@ -15,7 +15,7 @@
 #include <dlfcn.h>
 #endif
 #ifdef HAVE_RTHREADS
-#include "../frontend/libretro-rthreads.h"
+#include "../frontend/pcsxr-threads.h"
 #endif
 
 #include "main.h"
similarity index 98%
rename from frontend/libretro-rthreads.c
rename to frontend/pcsxr-threads.c
index 90067b1..1c1ff2e 100644 (file)
@@ -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 (file)
index 0000000..977830e
--- /dev/null
@@ -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 <threads.h>
+
+#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__
index 81c2e12..5d132d6 100644 (file)
@@ -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
index 9df3115..e52b648 100644 (file)
@@ -42,53 +42,7 @@ static int  rcdrom_isMediaInserted(void *stream) { return 0; }
 
 #endif
 
-#ifdef USE_C11_THREADS
-#include <threads.h>
-
-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)
index cefadd2..d88e147 100644 (file)
@@ -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)