diff --git a/CHANGELOG.md b/CHANGELOG.md index d55b9d41..9005d294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Allow configuring `JANET_THREAD_LOCAL` during builds to allow multi-threading on unknown compilers. - Make `ffi/write` append to a buffer instead of insert at 0 by default. - Add `os/getpid` to get the current process id. - Add `:out` option to `os/spawn` to be able to redirect stderr to stdout with pipes. diff --git a/meson.build b/meson.build index 247ae6f3..11cf185c 100644 --- a/meson.build +++ b/meson.build @@ -105,6 +105,9 @@ endif if get_option('arch_name') != '' conf.set('JANET_ARCH_NAME', get_option('arch_name')) endif +if get_option('thread_local_prefix') != '' + conf.set('JANET_THREAD_LOCAL', get_option('thread_local_prefix')) +endif jconf = configure_file(output : 'janetconf.h', configuration : conf) diff --git a/meson_options.txt b/meson_options.txt index 7b9b33af..d055c713 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -30,6 +30,7 @@ option('max_macro_expand', type : 'integer', min : 1, max : 8000, value : 200) option('stack_max', type : 'integer', min : 8096, max : 0x7fffffff, value : 0x7fffffff) option('arch_name', type : 'string', value: '') +option('thread_local_prefix', type : 'string', value: '') option('os_name', type : 'string', value: '') option('shared', type : 'boolean', value: true) option('cryptorand', type : 'boolean', value: true) diff --git a/src/conf/janetconf.h b/src/conf/janetconf.h index 35f1b58d..4accbf18 100644 --- a/src/conf/janetconf.h +++ b/src/conf/janetconf.h @@ -13,6 +13,7 @@ /* These settings all affect linking, so use cautiously. */ /* #define JANET_SINGLE_THREADED */ +/* #define JANET_THREAD_LOCAL _Thread_local */ /* #define JANET_NO_DYNAMIC_MODULES */ /* #define JANET_NO_NANBOX */ /* #define JANET_API __attribute__((visibility ("default"))) */ diff --git a/src/include/janet.h b/src/include/janet.h index 672552d1..8e6ca968 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -170,14 +170,12 @@ extern "C" { /* Also enable the thread library only if not single-threaded */ #ifdef JANET_SINGLE_THREADED #define JANET_THREAD_LOCAL -#undef JANET_THREADS -#elif defined(__GNUC__) +#elif !(defined(JANET_THREAD_LOCAL)) && defined(__GNUC__) #define JANET_THREAD_LOCAL __thread -#elif defined(_MSC_BUILD) +#elif !(defined(JANET_THREAD_LOCAL)) && defined(_MSC_BUILD) #define JANET_THREAD_LOCAL __declspec(thread) -#else +#elif !(defined(JANET_THREAD_LOCAL)) #define JANET_THREAD_LOCAL -#undef JANET_THREADS #endif /* Enable or disable dynamic module loading. Enabled by default. */