Support compiling without pthreads
authorPaul Cercueil <paul@crapouillou.net>
Sat, 11 Feb 2023 14:22:21 +0000 (14:22 +0000)
committernotaz <notasas@gmail.com>
Thu, 3 Aug 2023 17:50:59 +0000 (20:50 +0300)
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
frontend/libretro.c
frontend/libretro_core_options.h
libpcsxcore/cdriso.c
plugins/dfsound/spu.c

index 7b7ce5c..6e9d10c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,8 @@ CFLAGS += -Wall -ggdb -Iinclude -ffast-math
 ifndef DEBUG
 CFLAGS += -O2 -DNDEBUG
 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 32d0bec..e5b21d5 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 781c514..b9eaf77 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 f47fcfd..d0440e2 100644 (file)
@@ -30,8 +30,7 @@
 #include <process.h>
 #include <windows.h>
 #define strcasecmp _stricmp
-#define usleep(x) Sleep((x) / 1000)
-#else
+#elif HAVE_PTHREAD
 #include <pthread.h>
 #include <sys/time.h>
 #include <unistd.h>
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)
 {