From: Paul Cercueil Date: Sat, 11 Feb 2023 14:22:21 +0000 (+0000) Subject: Support compiling without pthreads X-Git-Tag: r24l~290^2~2 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78bb116f38e967174ce6255a51c9d19805e8fcb2;p=pcsx_rearmed.git Support compiling without pthreads 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 --- diff --git a/Makefile b/Makefile index 779f67a4..cf2ea886 100644 --- 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 diff --git a/Makefile.libretro b/Makefile.libretro index 35461804..9f196387 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -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 := diff --git a/frontend/libretro.c b/frontend/libretro.c index 60cd29d7..177b1500 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -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"; diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index a2c068f7..6875b57d 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -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", diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index 83677504..232a979f 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -36,18 +36,16 @@ #include #include #define strcasecmp _stricmp -#else +#elif HAVE_PTHREAD #include #include #include #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 @@ -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(§orbuffer_lock); @@ -1563,7 +1561,6 @@ static unsigned char * CALLBACK ISOgetBuffer_async(void) { pthread_mutex_unlock(§orbuffer_lock); return buffer + 12; } - #endif static unsigned char * CALLBACK ISOgetBuffer(void) { diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c index ebebd2a2..f5e8de50 100644 --- a/plugins/dfsound/spu.c +++ b/plugins/dfsound/spu.c @@ -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 #include @@ -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) {