Support compiling without pthreads
authorPaul Cercueil <paul@crapouillou.net>
Sat, 11 Feb 2023 14:22:21 +0000 (14:22 +0000)
committerPaul Cercueil <paul@crapouillou.net>
Sun, 23 Jul 2023 18:09:14 +0000 (20:09 +0200)
Add NO_PTHREAD option in the Makefile, which can be used on platforms
that don't support pthreads.

Since dfsound/spu.c disables threading support on Win32 and platform
defining NO_OS (Switch, 3DS, PSP Vita), mark them as not having
pthreads.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Makefile
Makefile.libretro
frontend/libretro.c
frontend/libretro_core_options.h
libpcsxcore/cdriso.c
plugins/dfsound/spu.c

index 779f67a..cf2ea88 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,8 @@ else
 CFLAGS += -O2 -DNDEBUG
 endif
 endif
-CFLAGS += -DHAVE_MMAP=$(if $(NO_MMAP),0,1)
+CFLAGS += -DHAVE_MMAP=$(if $(NO_MMAP),0,1) \
+         -DHAVE_PTHREAD=$(if $(NO_PTHREAD),0,1)
 CXXFLAGS += $(CFLAGS)
 #DRC_DBG = 1
 #PCNT = 1
index 3546180..9f19638 100644 (file)
@@ -210,6 +210,7 @@ else ifeq ($(platform), libnx)
    CFLAGS += -DARM -D__aarch64__=1 -march=armv8-a -mtune=cortex-a57 -mtp=soft -DHAVE_INTTYPES -DLSB_FIRST -ffast-math -mcpu=cortex-a57+crc+fp+simd -ffunction-sections
    CFLAGS += -ftree-vectorize
    CFLAGS += -Ifrontend/switch -ftree-vectorize
+   NO_PTHREAD=1
    LIBPTHREAD :=
    STATIC_LINKING=1
    BUILTIN_GPU = neon
@@ -263,6 +264,7 @@ else ifeq ($(platform), vita)
        DYNAREC = ari64
        ARCH = arm
        STATIC_LINKING = 1
+       NO_PTHREAD=1
 
 # CTR(3DS)
 else ifeq ($(platform), ctr)
@@ -270,7 +272,7 @@ else ifeq ($(platform), ctr)
        CC = $(DEVKITARM)/bin/arm-none-eabi-gcc$(EXE_EXT)
        CXX = $(DEVKITARM)/bin/arm-none-eabi-g++$(EXE_EXT)
        AR = $(DEVKITARM)/bin/arm-none-eabi-ar$(EXE_EXT)
-       CFLAGS += -DARM11 -D_3DS -DNO_OS -DNO_DYLIB -DNO_SOCKET -DTHREAD_ENABLED -DGPU_UNAI_USE_FLOATMATH -DGPU_UNAI_USE_FLOAT_DIV_MULTINV
+       CFLAGS += -DARM11 -D_3DS -DNO_OS -DNO_DYLIB -DNO_SOCKET -DGPU_UNAI_USE_FLOATMATH -DGPU_UNAI_USE_FLOAT_DIV_MULTINV
        CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard -marm -mfpu=vfp -mtp=soft
        CFLAGS += -Wall -mword-relocations
        CFLAGS += -fomit-frame-pointer -ffast-math -funroll-loops
@@ -511,6 +513,7 @@ ifneq ($(DEBUG),1)
 endif
        CFLAGS += -D__WIN32__ -DNO_DYLIB
        MMAP_WIN32=1
+       NO_PTHREAD=1
        MAIN_LDLIBS += -lws2_32
        LIBPTHREAD :=
        LIBDL :=
index 60cd29d..177b150 100644 (file)
@@ -2098,28 +2098,28 @@ static void update_variables(bool in_flight)
          spu_config.iUseThread = 0;
    }
 
-#ifndef _WIN32
-   var.value = NULL;
-   var.key = "pcsx_rearmed_async_cd";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
-   {
-      if (strcmp(var.value, "async") == 0)
-      {
-         Config.AsyncCD = 1;
-         Config.CHD_Precache = 0;
-      }
-      else if (strcmp(var.value, "sync") == 0)
-      {
-         Config.AsyncCD = 0;
-         Config.CHD_Precache = 0;
-      }
-      else if (strcmp(var.value, "precache") == 0)
-      {
-         Config.AsyncCD = 0;
-         Config.CHD_Precache = 1;
-      }
+   if (HAVE_PTHREAD) {
+          var.value = NULL;
+          var.key = "pcsx_rearmed_async_cd";
+          if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
+          {
+                 if (strcmp(var.value, "async") == 0)
+                 {
+                        Config.AsyncCD = 1;
+                        Config.CHD_Precache = 0;
+                 }
+                 else if (strcmp(var.value, "sync") == 0)
+                 {
+                        Config.AsyncCD = 0;
+                        Config.CHD_Precache = 0;
+                 }
+                 else if (strcmp(var.value, "precache") == 0)
+                 {
+                        Config.AsyncCD = 0;
+                        Config.CHD_Precache = 1;
+                 }
+       }
    }
-#endif
 
    var.value = NULL;
    var.key = "pcsx_rearmed_noxadecoding";
index a2c068f..6875b57 100644 (file)
@@ -750,7 +750,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
       },
       "enabled",
    },
-#if !defined(THREAD_ENABLED) && !defined(_WIN32) && !defined(NO_OS)
+#if HAVE_PTHREAD
    {
       "pcsx_rearmed_spu_thread",
       "Threaded SPU",
@@ -765,7 +765,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
       },
       "disabled",
    },
-#endif // THREAD_ENABLED
+#endif // HAVE_PTHREAD
    {
       "pcsx_rearmed_show_input_settings",
       "Show Input Settings",
index 8367750..232a979 100644 (file)
 #include <process.h>
 #include <windows.h>
 #define strcasecmp _stricmp
-#else
+#elif HAVE_PTHREAD
 #include <pthread.h>
 #include <sys/time.h>
 #include <unistd.h>
 #endif
 
-#ifndef _WIN32
 // to enable the USE_READ_THREAD code, fix:
 // - https://github.com/notaz/pcsx_rearmed/issues/257
 // - ISOgetBufferSub to not race with async code
-//#define USE_READ_THREAD
-#endif
+#define USE_READ_THREAD 0 //HAVE_PTHREAD
 
 #ifdef USE_LIBRETRO_VFS
 #include <streams/file_stream_transforms.h>
@@ -1079,7 +1077,7 @@ static int opensbifile(const char *isoname) {
        return LoadSBI(sbiname, s);
 }
 
-#ifndef USE_READ_THREAD
+#if !USE_READ_THREAD
 static void readThreadStop() {}
 static void readThreadStart() {}
 #else
@@ -1497,7 +1495,7 @@ static int cdread_2048(FILE *f, unsigned int base, void *dest, int sector)
        return 12*2 + ret;
 }
 
-#ifdef USE_READ_THREAD
+#if USE_READ_THREAD
 
 static int cdread_async(FILE *f, unsigned int base, void *dest, int sector) {
   boolean found = FALSE;
@@ -1555,7 +1553,7 @@ static unsigned char * CALLBACK ISOgetBuffer_chd(void) {
 }
 #endif
 
-#ifdef USE_READ_THREAD
+#if USE_READ_THREAD
 static unsigned char * CALLBACK ISOgetBuffer_async(void) {
   unsigned char *buffer;
   pthread_mutex_lock(&sectorbuffer_lock);
@@ -1563,7 +1561,6 @@ static unsigned char * CALLBACK ISOgetBuffer_async(void) {
   pthread_mutex_unlock(&sectorbuffer_lock);
   return buffer + 12;
 }
-
 #endif
 
 static unsigned char * CALLBACK ISOgetBuffer(void) {
index ebebd2a..f5e8de5 100644 (file)
@@ -18,9 +18,6 @@
  *                                                                         *
  ***************************************************************************/
 
-#if !defined(THREAD_ENABLED) && !defined(_WIN32) && !defined(NO_OS)
-#define THREAD_ENABLED 1
-#endif
 #include "stdafx.h"
 
 #define _IN_SPU
@@ -832,7 +829,7 @@ static void do_samples_finish(int *SSumLR, int ns_to,
 
 // optional worker thread handling
 
-#if defined(THREAD_ENABLED) || defined(WANT_THREAD_CODE)
+#if HAVE_PTHREAD || defined(WANT_THREAD_CODE)
 
 // worker thread state
 static struct spu_worker {
@@ -1087,7 +1084,7 @@ static void sync_worker_thread(int force) {}
 
 static const void * const worker = NULL;
 
-#endif // THREAD_ENABLED
+#endif // HAVE_PTHREAD || defined(WANT_THREAD_CODE)
 
 ////////////////////////////////////////////////////////////////////////
 // MAIN SPU FUNCTION
@@ -1368,7 +1365,7 @@ static void RemoveStreams(void)
 /* special code for TI C64x DSP */
 #include "spu_c64x.c"
 
-#elif defined(THREAD_ENABLED)
+#elif HAVE_PTHREAD
 
 #include <pthread.h>
 #include <semaphore.h>
@@ -1467,7 +1464,7 @@ static void exit_spu_thread(void)
  worker = NULL;
 }
 
-#else // if !THREAD_ENABLED
+#else // if !HAVE_PTHREAD
 
 static void init_spu_thread(void)
 {