diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-15 15:34:07 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-15 15:34:07 -0700 |
commit | 4dfeb1c3a84b13188c22e158c5947c68964cddff (patch) | |
tree | 211536213451e145357727e51f3d1c48a127ea2f /src/emscripten-optimizer/istring.h | |
parent | f2905f962984df939555aad134c48a194b9e270d (diff) | |
download | binaryen-4dfeb1c3a84b13188c22e158c5947c68964cddff.tar.gz binaryen-4dfeb1c3a84b13188c22e158c5947c68964cddff.tar.bz2 binaryen-4dfeb1c3a84b13188c22e158c5947c68964cddff.zip |
Function parallelism (#343)
* allow traversals to mark themselves as function-parallel, in which case we run them using a thread pool. also mark some thread-safety risks (interned strings, arena allocators) with assertions they modify only on the main thread
Diffstat (limited to 'src/emscripten-optimizer/istring.h')
-rw-r--r-- | src/emscripten-optimizer/istring.h | 24 |
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) { |