Skip to content

Commit

Permalink
Don't use threads stuff in Emscripten
Browse files Browse the repository at this point in the history
  • Loading branch information
ampli committed Jan 16, 2023
1 parent 1019ee2 commit cfc0a91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions link-grammar/dict-common/regex-morph.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
/* */
/*************************************************************************/

#if HAVE_THREADS_H
#if HAVE_THREADS_H && !__EMSCRIPTEN__
#include <threads.h>
#endif
#endif // HAVE_THREADS_H && !__EMSCRIPTEN__

/**
* Support for the regular-expression based token matching system
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions link-grammar/parse/count.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#include <limits.h>
#include <inttypes.h> // PRIu64
#if HAVE_THREADS_H
#if HAVE_THREADS_H && !__EMSCRIPTEN__
#include <threads.h>
#endif /* HAVE_THREADS_H */
#endif /* HAVE_THREADS_H && !__EMSCRIPTEN__ */

#include "link-includes.h"
#include "api-structures.h"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 */
Expand Down

0 comments on commit cfc0a91

Please sign in to comment.