diff --git a/.gitignore b/.gitignore index e99eb7c618..6ddc45c129 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,6 @@ data/th/old_words/** # Visual Studio keeps adding the directory ".vs". If it got added while # rebasing and it is not git-ignored, it somehow breaks the rebase. .vs +# a.wasm is created by "emcc" (in "emconfigure ./configure"). +# For now just ignore it. +a.wasm diff --git a/configure.ac b/configure.ac index d63a25fd6a..be1556b1fe 100644 --- a/configure.ac +++ b/configure.ac @@ -119,38 +119,28 @@ AC_CHECK_FUNCS(prctl) AC_DEFINE(__STDC_FORMAT_MACROS) AC_DEFINE(__STDC_LIMIT_MACROS) -# Don't use thread functions with Emscripten. -# Emscripten does not like threads. -if test "$EMSCRIPTEN" != ''; then - AC_CHECK_DEFINE(__EMSCRIPTEN__, [emscripten=yes], - [AC_MSG_ERROR([EMSCRIPTEN environment variable found, but emcc is not used])]) -fi - -if test "x$emscripten" != "xyes"; then - - # Check for a keyword for Thread Local Storage declaration. - # If found - define TLS to it. - lg_tls=no - AX_TLS(,:) - test "$ac_cv_tls" != "none" && lg_tls=yes - - AX_PTHREAD - if test -n "$ax_pthread_ok"; then - CC="${PTHREAD_CC:-CC}" - dnl #CCX="${PTHREAD_CC:-CCX}" - - dnl Currently, libtool uses --nostdlib when linking shared libraries, - dnl which causes the -pthread flag to be ignored. Try to work around that - dnl by explicitly specifying the pthread library unless it is already set. - if test -z "$PTHREAD_LIBS"; then - PTHREAD_LIBS=-lpthread - fi +# Check for a keyword for Thread Local Storage declaration. +# If found - define TLS to it. +lg_tls=no +AX_TLS(,:) +test "$ac_cv_tls" != "none" && lg_tls=yes + +AX_PTHREAD +if test -n "$ax_pthread_ok"; then + CC="${PTHREAD_CC:-CC}" + dnl #CCX="${PTHREAD_CC:-CCX}" + + dnl Currently, libtool uses --nostdlib when linking shared libraries, + dnl which causes the -pthread flag to be ignored. Try to work around that + dnl by explicitly specifying the pthread library unless it is already set. + if test -z "$PTHREAD_LIBS"; then + PTHREAD_LIBS=-lpthread fi - - dnl Check if we can use C11 threads functions - AC_CHECK_HEADERS_ONCE([threads.h]) fi +dnl Check if we can use C11 threads functions +AC_CHECK_HEADERS_ONCE([threads.h]) + dnl If the visibility __attribute__ is supported, define HAVE_VISIBILITY dnl and a variable CFLAG_VISIBILITY, to be added to CFLAGS/CXXFLAGS. LG_C_ATTRIBUTE_VISIBILITY diff --git a/link-grammar/dict-common/regex-morph.c b/link-grammar/dict-common/regex-morph.c index bfbf0094c7..016058aa19 100644 --- a/link-grammar/dict-common/regex-morph.c +++ b/link-grammar/dict-common/regex-morph.c @@ -10,9 +10,9 @@ /* */ /*************************************************************************/ -#if HAVE_THREADS_H +#if HAVE_THREADS_H && !__EMSCRIPTEN__ #include -#endif +#endif // HAVE_THREADS_H && !__EMSCRIPTEN__ /** * Support for the regular-expression based token matching system @@ -177,7 +177,7 @@ static void alloc_key(void) static pcre2_match_data* alloc_match_data(void) { -#if HAVE_THREADS_H +#if HAVE_THREADS_H && !__EMSCRIPTEN__ call_once(&call_once_flag, alloc_key); pcre2_match_data *pmd = (pcre2_match_data *) tss_get(re_md_key); @@ -194,7 +194,7 @@ static pcre2_match_data* alloc_match_data(void) pmd = pcre2_match_data_create(MAX_CAPTURE_GROUPS, NULL); if (pmd) return pmd; -#endif // HAVE_THREADS_H +#endif // HAVE_THREADS_H && !__EMSCRIPTEN__ prt_error("Error: pcre2_match_data_create() failed\n"); return NULL; } diff --git a/link-grammar/parse/count.c b/link-grammar/parse/count.c index 921de47484..731a7a7334 100644 --- a/link-grammar/parse/count.c +++ b/link-grammar/parse/count.c @@ -14,9 +14,9 @@ #include #include // PRIu64 -#if HAVE_THREADS_H +#if HAVE_THREADS_H && !__EMSCRIPTEN__ #include -#endif /* HAVE_THREADS_H */ +#endif /* HAVE_THREADS_H && !__EMSCRIPTEN__ */ #include "link-includes.h" #include "api-structures.h" @@ -124,7 +124,7 @@ struct count_context_s #define MAX_TABLE_SIZE(s) (s / 10) /* Low load factor, for speed */ #define MAX_LOG2_TABLE_SIZE ((sizeof(size_t)==4) ? 25 : 34) -#if HAVE_THREADS_H +#if HAVE_THREADS_H && !__EMSCRIPTEN__ /* Each thread will get it's own version of the `kept_table`. * If the program creates zillions of threads, then there will * be a mem-leak if this table is not released when each thread @@ -147,7 +147,7 @@ static void make_key(void) { tss_create(&key, free_tls_table); } -#endif /* HAVE_THREADS_H */ +#endif /* HAVE_THREADS_H && !__EMSCRIPTEN__ */ /** * Allocate memory for the connector-pair table and initialize table-size @@ -164,14 +164,14 @@ static void table_alloc(count_context_t *ctxt, unsigned int shift) static TLS Table_connector **kept_table = NULL; static TLS unsigned int log2_kept_table_size = 0; -#if HAVE_THREADS_H +#if HAVE_THREADS_H && !__EMSCRIPTEN__ // Install a thread-exit handler, to free kept_table on thread-exit. static once_flag flag = ONCE_FLAG_INIT; call_once(&flag, make_key); if (NULL == kept_table) tss_set(key, &kept_table); -#endif /* HAVE_THREADS_H */ +#endif /* HAVE_THREADS_H && !__EMSCRIPTEN__ */ if (shift == 0) shift = ctxt->log2_table_size + 1; /* Double the table size */