summaryrefslogtreecommitdiff
path: root/src/emscripten-optimizer/istring.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/emscripten-optimizer/istring.h')
-rw-r--r--src/emscripten-optimizer/istring.h24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/emscripten-optimizer/istring.h b/src/emscripten-optimizer/istring.h
index 8e91d044d..149f77d23 100644
--- a/src/emscripten-optimizer/istring.h
+++ b/src/emscripten-optimizer/istring.h
@@ -29,6 +29,8 @@
#include <stdio.h>
#include <assert.h>
+#include "support/threads.h"
+
namespace cashew {
struct IString {
@@ -66,22 +68,24 @@ struct IString {
typedef std::unordered_set<const char *, CStringHash, CStringEqual> StringSet;
static StringSet* strings = new StringSet();
- if (reuse) {
- auto result = strings->insert(s); // if already present, does nothing
- str = *(result.first);
- } else {
- auto existing = strings->find(s);
- if (existing == strings->end()) {
+ auto existing = strings->find(s);
+
+ if (existing == strings->end()) {
+ // the StringSet cache is a global shared structure, which should
+ // not be modified by multiple threads at once.
+ assert(!wasm::ThreadPool::isRunning());
+ if (!reuse) {
size_t len = strlen(s) + 1;
char *copy = (char*)malloc(len); // XXX leaked
strncpy(copy, s, len);
s = copy;
- strings->insert(s);
- } else {
- s = *existing;
}
- str = s;
+ strings->insert(s);
+ } else {
+ s = *existing;
}
+
+ str = s;
}
void set(const IString &s) {