From fdc6ba3bec8965e7ca9c0cc97c486353f427afa6 Mon Sep 17 00:00:00 2001 From: Nick Vatamaniuc Date: Mon, 13 May 2024 00:38:19 -0400 Subject: [PATCH] Add CONFIG_NO_WORKER Makefile option This option eliminates the dependency on the pthread library. This mode is already toggled on _WIN32 and/or EMSCRIPTEN is detected, here we just allow the user to toggle it at will at the top level. This slightly reduce the code size as well, and may allow compiling this library in some embedded contexts where pthread is not available or is broken. --- Makefile | 3 +++ quickjs-libc.c | 2 +- quickjs.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index cf88a723a..715370e81 100644 --- a/Makefile +++ b/Makefile @@ -148,6 +148,9 @@ ifeq ($(shell $(CC) -o /dev/null compat/test-closefrom.c 2>/dev/null && echo 1), DEFINES+=-DHAVE_CLOSEFROM endif endif +ifdef CONFIG_NO_WORKER +DEFINES+=-DCONFIG_NO_WORKER +endif CFLAGS+=$(DEFINES) CFLAGS_DEBUG=$(CFLAGS) -O0 diff --git a/quickjs-libc.c b/quickjs-libc.c index 141f79f3c..93e0d063b 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -64,7 +64,7 @@ typedef sig_t sighandler_t; #endif -#if !defined(_WIN32) +#if !defined(_WIN32) && !defined(CONFIG_NO_WORKER) /* enable the os.Worker API. IT relies on POSIX threads */ #define USE_WORKER #endif diff --git a/quickjs.c b/quickjs.c index 642ae3429..0d789199f 100644 --- a/quickjs.c +++ b/quickjs.c @@ -68,7 +68,7 @@ /* define to include Atomics.* operations which depend on the OS threads */ -#if !defined(EMSCRIPTEN) +#if !defined(EMSCRIPTEN) && !defined(CONFIG_NO_WORKER) #define CONFIG_ATOMICS #endif