spu: use USE_ASYNC_ like the other threaded parts
authornotaz <notasas@gmail.com>
Sun, 15 Mar 2026 23:55:15 +0000 (01:55 +0200)
committernotaz <notasas@gmail.com>
Mon, 16 Mar 2026 00:11:36 +0000 (02:11 +0200)
also drop no longer used P_HAVE_PTHREAD

Makefile
Makefile.libretro
configure
frontend/libretro.c
frontend/libretro_core_options.h
jni/Android.mk
plugins/dfsound/externals.h
plugins/dfsound/freeze.c
plugins/dfsound/reverb.c
plugins/dfsound/spu.c
plugins/spunull/spunull.c

index c13e21e..07f785e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -75,7 +75,6 @@ LDFLAGS += $(FSECTIONS_LDFLAGS)
 endif
 endif # NO_FSECTIONS
 CFLAGS += -DP_HAVE_MMAP=$(if $(NO_MMAP),0,1) \
-         -DP_HAVE_PTHREAD=$(if $(NO_PTHREAD),0,1) \
          -DP_HAVE_POSIX_MEMALIGN=$(if $(NO_POSIX_MEMALIGN),0,1) \
          -DDISABLE_MEM_LUTS=0
 CXXFLAGS += $(CFLAGS)
@@ -137,6 +136,11 @@ frontend/libretro.o: CFLAGS += -DUSE_ASYNC_GPU
 frontend/menu.o: CFLAGS += -DUSE_ASYNC_GPU
 USE_RTHREADS := 1
 endif
+ifeq "$(USE_ASYNC_SPU)" "1"
+frontend/libretro.o: CFLAGS += -DUSE_ASYNC_SPU
+frontend/menu.o: CFLAGS += -DUSE_ASYNC_SPU
+USE_RTHREADS := 1
+endif
 
 # dynarec
 ifeq "$(DYNAREC)" "lightrec"
@@ -236,6 +240,9 @@ ifeq "$(HAVE_C64_TOOLS)" "1"
 plugins/dfsound/%.o: CFLAGS += -DC64X_DSP -DWANT_THREAD_CODE
 frontend/menu.o: CFLAGS += -DC64X_DSP
 endif
+ifeq "$(USE_ASYNC_SPU)" "1"
+plugins/dfsound/%.o: CFLAGS += -DUSE_ASYNC_SPU
+endif
 ifneq ($(findstring oss,$(SOUND_DRIVERS)),)
 plugins/dfsound/out.o: CFLAGS += -DHAVE_OSS
 OBJS += plugins/dfsound/oss.o
index 97813da..52d690f 100644 (file)
@@ -6,6 +6,7 @@ HAVE_CHD ?= 1
 HAVE_PHYSICAL_CDROM ?= 1
 USE_ASYNC_CDROM ?= 1
 USE_ASYNC_GPU ?= 1
+USE_ASYNC_SPU ?= 1
 USE_LIBRETRO_VFS ?= 0
 NDRC_THREAD ?= 1
 GNU_LINKER ?= 1
@@ -282,7 +283,6 @@ else ifeq ($(platform), libnx)
    CFLAGS += -ftree-vectorize
    CFLAGS += -Ifrontend/switch
    NO_POSIX_MEMALIGN := 1
-   NO_PTHREAD=1
    NO_MMAP := 1 # for psxmem
    LIBPTHREAD :=
    WANT_ZLIB = 0
@@ -310,13 +310,13 @@ else ifeq ($(platform), psl1ght)
        NO_UNDEF_CHECK := 1
        STATIC_LINKING := 1
        NO_MMAP := 1
-       NO_PTHREAD := 1
        LIBPTHREAD :=
        LIBDL :=
        NEED_SYSCONF := 1
        HAVE_PHYSICAL_CDROM = 0
        USE_ASYNC_CDROM = 0
        USE_ASYNC_GPU = 0
+       USE_ASYNC_SPU = 0
 
 # PSP
 else ifeq ($(platform), psp1)
@@ -413,7 +413,6 @@ else ifneq (,$(filter $(platform),ngc wii wiiu))
        CFLAGS += -DGEKKO -mcpu=750 -meabi -mhard-float
        CFLAGS += -DNO_DYLIB
        STATIC_LINKING := 1
-       NO_PTHREAD := 1
        NO_MMAP := 1
        NO_POSIX_MEMALIGN := 1
        LIBDL :=
@@ -422,6 +421,7 @@ else ifneq (,$(filter $(platform),ngc wii wiiu))
        HAVE_PHYSICAL_CDROM = 0
        USE_ASYNC_CDROM = 0
        USE_ASYNC_GPU = 0
+       USE_ASYNC_SPU = 0
 
 # QNX
 else ifeq ($(platform), qnx)
@@ -595,7 +595,6 @@ else ifeq ($(platform), miyoo)
 # Emscripten
 else ifeq ($(platform), emscripten)
    TARGET  := $(TARGET_NAME)_libretro_$(platform).bc
-   pthread ?= 0
    fpic    := -fPIC
    NO_MMAP = 1
    # we can use -lz for emscripten's built-in zlib port
@@ -603,24 +602,11 @@ else ifeq ($(platform), emscripten)
    CFLAGS_OPT = -O2
    CFLAGS += -DNO_DYLIB -DNO_SOCKET
    CFLAGS += -msimd128 -ftree-vectorize
-   # when compiling with pthreads...
-   ifneq ($(pthread), 0)
-      # use -lpthread
-      LIBPTHREAD := -lpthread
-      NO_PTHREAD=0
-      # but we don't want to include libretro-common's rthread object files here
-      USE_RTHREADS=0
-      USE_ASYNC_CDROM=0
-      USE_ASYNC_GPU=0
-      # so we disable some uses of threads within pcsx_rearmed.
-      # is this a good solution? I don't know!
-   else
-      LIBPTHREAD :=
-      USE_RTHREADS=0
-      USE_ASYNC_CDROM=0
-      USE_ASYNC_GPU=0
-      NO_PTHREAD=1
-   endif
+   LIBPTHREAD :=
+   USE_RTHREADS=0
+   USE_ASYNC_CDROM=0
+   USE_ASYNC_GPU=0
+   USE_ASYNC_SPU=0
    DYNAREC =
    STATIC_LINKING = 1
    HAVE_PHYSICAL_CDROM = 0
@@ -635,12 +621,12 @@ ifneq ($(DEBUG),1)
 endif
        CFLAGS += -D__WIN32__ -DNO_DYLIB
        MMAP_WIN32=1
-       NO_PTHREAD=1
        MAIN_LDLIBS += -lws2_32
        LIBPTHREAD :=
        LIBDL :=
        LIBM :=
        USE_LIBRETRO_VFS = 1
+       USE_ASYNC_SPU = 0 # uses posix semaphore.h
 endif
 
 CFLAGS += $(fpic)
index c0bbb6f..b6a2150 100755 (executable)
--- a/configure
+++ b/configure
@@ -684,6 +684,7 @@ fi
 if [ "$multithreading" = "yes" ]; then
   echo "USE_ASYNC_CDROM = 1" >> $config_mak
   echo "USE_ASYNC_GPU = 1" >> $config_mak
+  echo "USE_ASYNC_SPU = 1" >> $config_mak
   echo "NDRC_THREAD = 1" >> $config_mak
 fi
 
index 32a8a9b..22898b5 100644 (file)
@@ -2608,7 +2608,7 @@ static void update_variables(bool in_flight)
          spu_config.iUseInterpolation = 0;
    }
 
-#if P_HAVE_PTHREAD
+#ifdef USE_ASYNC_SPU
    var.value = NULL;
    var.key = "pcsx_rearmed_spu_thread";
    if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
@@ -2618,7 +2618,7 @@ static void update_variables(bool in_flight)
          spu_config.iUseThread = 1;
       else
          spu_config.iUseThread = 0;
-      if (spu_config.iUseThread != spu_thread_old)
+      if (spu_config.iUseThread != spu_thread_old && SPU_configure)
          SPU_configure();
    }
 #endif
index 8b02f7c..eb0c3b5 100644 (file)
@@ -907,7 +907,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
       },
       "enabled",
    },
-#if P_HAVE_PTHREAD
+#ifdef USE_ASYNC_SPU
    {
       "pcsx_rearmed_spu_thread",
       "Threaded SPU",
@@ -922,7 +922,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
       },
       "disabled",
    },
-#endif // P_HAVE_PTHREAD
+#endif
    {
       "pcsx_rearmed_show_input_settings",
       "Show Input Settings",
index 6f2bfd1..3e016ca 100644 (file)
@@ -8,6 +8,7 @@ $(shell cd "$(LOCAL_PATH)" && (rm ../include/revision.h_))
 USE_LIBRETRO_VFS ?= 0
 USE_ASYNC_CDROM ?= 1
 USE_ASYNC_GPU ?= 1
+USE_ASYNC_SPU ?= 1
 USE_RTHREADS ?= 0
 NDRC_THREAD ?= 1
 
@@ -244,6 +245,10 @@ SOURCES_C += $(GPU_DIR)/gpu_async.c
 COREFLAGS += -DUSE_ASYNC_GPU
 USE_RTHREADS := 1
 endif
+ifeq ($(USE_ASYNC_SPU),1)
+COREFLAGS += -DUSE_ASYNC_SPU
+USE_RTHREADS := 1
+endif
 ifeq ($(USE_RTHREADS),1)
 SOURCES_C += \
              $(FRONTEND_DIR)/pcsxr-threads.c \
index 1754371..05471de 100644 (file)
@@ -262,7 +262,7 @@ typedef struct
  sample_buf_rvb  sb_rvb; // for reverb filtering\r
  int             interpolation;\r
 \r
-#if P_HAVE_PTHREAD || defined(WANT_THREAD_CODE)\r
+#if defined(USE_ASYNC_SPU) || defined(WANT_THREAD_CODE)\r
  sample_buf    * sb_thread;\r
  sample_buf      sb_thread_[MAXCHAN+1];\r
 #endif\r
index be43c2c..046ec9a 100644 (file)
@@ -257,7 +257,7 @@ long DoFreeze(int ulFreezeMode, struct SPUFreeze * pF, unsigned short **ram,
  if (!pF || !pF2) return 0;                            // first check\r
  pFO = pF2;\r
 \r
-#if P_HAVE_PTHREAD || defined(WANT_THREAD_CODE)\r
+#if defined(USE_ASYNC_SPU) || defined(WANT_THREAD_CODE)\r
  sb_rvb = (sample_buf_rvb *)&spu.sb_thread[MAXCHAN];\r
 #endif\r
  if(ulFreezeMode)                                      // info or save?\r
index 99f84e6..a40fb58 100644 (file)
@@ -115,7 +115,7 @@ static void MixREVERB(int *SSumLR, int *RVB, int ns_to, int curr_addr,
  int vIIR = rvb->vIIR;\r
  int ns;\r
 \r
-#if P_HAVE_PTHREAD || defined(WANT_THREAD_CODE)\r
+#if defined(USE_ASYNC_SPU) || defined(WANT_THREAD_CODE)\r
  // this is reusing sb_thread[] due to complications with spu_c64x\r
  //sb = (sample_buf_rvb *)&spu.sb_thread[MAXCHAN];\r
 #endif\r
index b4ac7b6..76f76af 100644 (file)
@@ -695,7 +695,7 @@ static void do_samples_finish(int *SSumLR, int ns_to,
 
 // optional worker thread handling
 
-#if P_HAVE_PTHREAD || defined(WANT_THREAD_CODE)
+#if defined(USE_ASYNC_SPU) || defined(WANT_THREAD_CODE)
 
 // worker thread state
 static struct spu_worker {
@@ -990,7 +990,7 @@ static void sync_worker_thread(int force_no_thread) {}
 
 static const void * const worker = NULL;
 
-#endif // P_HAVE_PTHREAD || defined(WANT_THREAD_CODE)
+#endif // defined(USE_ASYNC_SPU) || defined(WANT_THREAD_CODE)
 
 ////////////////////////////////////////////////////////////////////////
 // MAIN SPU FUNCTION
@@ -1298,7 +1298,7 @@ static void RemoveStreams(void)
 /* special code for TI C64x DSP */
 #include "spu_c64x.c"
 
-#elif P_HAVE_PTHREAD
+#elif defined(USE_ASYNC_SPU)
 
 #include "../../frontend/pcsxr-threads.h"
 #ifdef _3DS
@@ -1356,6 +1356,9 @@ static void init_spu_thread(void)
 {
  int ret;
 
+ spu.sb_thread = spu.sb_thread_;
+ if (!spu_config.iUseThread)
+  return;
  if (worker)
   return;
  worker = calloc(1, sizeof(*worker));
@@ -1396,7 +1399,7 @@ static void exit_spu_thread(void)
  worker = NULL;
 }
 
-#else // if !P_HAVE_PTHREAD
+#else // if !defined(USE_ASYNC_SPU)
 
 static void init_spu_thread(void)
 {
@@ -1438,11 +1441,7 @@ long CALLBACK SPUinit(void)
  if (spu_config.iVolume == 0)
   spu_config.iVolume = 768; // 1024 is 1.0
 
- spu.sb_thread = spu.sb_thread_;
-#ifndef C64X_DSP
- if (spu_config.iUseThread)
-#endif
-  init_spu_thread();
+ init_spu_thread();
 
  for (i = 0; i < MAXCHAN; i++)                         // loop sound channels
   {
@@ -1504,10 +1503,12 @@ long CALLBACK SPUshutdown(void)
 
 void CALLBACK SPUconfigure(void)
 {
+#ifndef C64X_DSP
  if (spu.bSpuInit && spu_config.iUseThread)
   init_spu_thread();
  else
   exit_spu_thread();
+#endif
 }
 
 // SETUP CALLBACKS
index cd27205..40c8fe3 100644 (file)
@@ -443,91 +443,6 @@ long DoFreeze(int ulFreezeMode, SPUFreeze_t * pF, unsigned short **ram,
  return 1;
 }
 
-
-//////////////////////////////////////////////////////////////////////// 
-//////////////////////////////////////////////////////////////////////// 
-//////////////////////////////////////////////////////////////////////// 
-// UNUSED WINDOWS FUNCS... YOU SHOULDN'T USE THEM IN LINUX
-
-long CALLBACK SPUconfigure(void)
-{
- return 0;
-}
-
-void CALLBACK SPUabout(void)
-{
-}
-
-//////////////////////////////////////////////////////////////////////// 
-//////////////////////////////////////////////////////////////////////// 
-//////////////////////////////////////////////////////////////////////// 
-// OLD PSEMU 1 FUNCS... YOU SHOULDN'T USE THEM
-
-unsigned short CALLBACK SPUgetOne(unsigned long val) 
-{ 
- if(spuAddr!=0xffffffff) 
-  { 
-   return SPUreadDMA(); 
-  } 
- if(val>=512*1024) val=512*1024-1; 
- return spuMem[val>>1]; 
-} 
-void CALLBACK SPUputOne(unsigned long val,unsigned short data) 
-{ 
- if(spuAddr!=0xffffffff) 
-  { 
-   SPUwriteDMA(data); 
-   return; 
-  } 
- if(val>=512*1024) val=512*1024-1; 
- spuMem[val>>1] = data; 
-} 
-void CALLBACK SPUplaySample(unsigned char ch) 
-{ 
-} 
-void CALLBACK SPUsetAddr(unsigned char ch, unsigned short waddr) 
-{ 
- //s_chan[ch].pStart=spuMemC+((unsigned long) waddr<<3); 
-} 
-void CALLBACK SPUsetPitch(unsigned char ch, unsigned short pitch) 
-{ 
- //SetPitch(ch,pitch); 
-} 
-void CALLBACK SPUsetVolumeL(unsigned char ch, short vol) 
-{ 
- //SetVolumeL(ch,vol); 
-} 
-void CALLBACK SPUsetVolumeR(unsigned char ch, short vol) 
-{ 
- //SetVolumeR(ch,vol); 
-}                
-void CALLBACK SPUstartChannels1(unsigned short channels) 
-{ 
- //SoundOn(0,16,channels); 
-} 
-void CALLBACK SPUstartChannels2(unsigned short channels) 
-{ 
- //SoundOn(16,24,channels); 
-} 
-void CALLBACK SPUstopChannels1(unsigned short channels) 
-{ 
- //SoundOff(0,16,channels); 
-} 
-void CALLBACK SPUstopChannels2(unsigned short channels) 
-{ 
- //SoundOff(16,24,channels); 
-} 
-
 void CALLBACK SPUregisterScheduleCb(void (CALLBACK *callback)(unsigned int))
 {
 }