diff options
-rw-r--r-- | src/binaryen-c.cpp | 33 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js.txt | 24 |
2 files changed, 29 insertions, 28 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index a824d77f7..842d96f69 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -60,6 +60,13 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) { } } +// Mutexes (global for now; in theory if multiple modules +// are used at once this should be optimized to be per- +// module, but likely it doesn't matter) + +static std::mutex BinaryenFunctionMutex; +static std::mutex BinaryenFunctionTypeMutex; + // Tracing support static int tracing = 0; @@ -137,9 +144,8 @@ BinaryenFunctionTypeRef BinaryenAddFunctionType(BinaryenModuleRef module, const // Lock. This can be called from multiple threads at once, and is a // point where they all access and modify the module. - static std::mutex BinaryenAddFunctionTypeMutex; { - std::lock_guard<std::mutex> lock(BinaryenAddFunctionTypeMutex); + std::lock_guard<std::mutex> lock(BinaryenFunctionTypeMutex); wasm->addFunctionType(ret); } @@ -728,9 +734,8 @@ BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module, const char* na // Lock. This can be called from multiple threads at once, and is a // point where they all access and modify the module. - static std::mutex BinaryenAddFunctionMutex; { - std::lock_guard<std::mutex> lock(BinaryenAddFunctionMutex); + std::lock_guard<std::mutex> lock(BinaryenFunctionMutex); wasm->addFunction(ret); } @@ -1104,27 +1109,23 @@ BinaryenFunctionTypeRef BinaryenGetFunctionTypeBySignature(BinaryenModuleRef mod } auto* wasm = (Module*)module; - auto* test = new FunctionType; - test->result = WasmType(result); + FunctionType test; + test.result = WasmType(result); for (BinaryenIndex i = 0; i < numParams; i++) { - test->params.push_back(WasmType(paramTypes[i])); + test.params.push_back(WasmType(paramTypes[i])); } - // Lock. This can be called from multiple threads at once, and is a - // point where they all access and modify the module. - static std::mutex BinaryenAddFunctionTypeMutex; + // Lock. Guard against reading the list while types are being added. { - std::lock_guard<std::mutex> lock(BinaryenAddFunctionTypeMutex); + std::lock_guard<std::mutex> lock(BinaryenFunctionTypeMutex); for (BinaryenIndex i = 0; i < wasm->functionTypes.size(); i++) { - FunctionType* current = wasm->functionTypes[i].get(); - if (current->structuralComparison(*test)) { - delete test; - return current; + FunctionType* curr = wasm->functionTypes[i].get(); + if (curr->structuralComparison(test)) { + return curr; } } } - delete test; return NULL; } diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index 43591bec2..59cf1ab10 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -1106,7 +1106,7 @@ int main() { expressions[5] = BinaryenConst(the_module, BinaryenLiteralFloat32(NAN)); expressions[6] = BinaryenConst(the_module, BinaryenLiteralFloat64(NAN)); { - BinaryenIndex paramTypes[] = { 1, 2, 3, 4 }; + BinaryenType paramTypes[] = { 1, 2, 3, 4 }; functionTypes[0] = BinaryenAddFunctionType(the_module, "iiIfF", 1, paramTypes, 4); } expressions[7] = BinaryenConst(the_module, BinaryenLiteralInt32(1)); @@ -1295,7 +1295,7 @@ int main() { expressions[190] = BinaryenBinary(the_module, 62, expressions[188], expressions[189]); { BinaryenExpressionRef children[] = { 0 }; - expressions[191] = BinaryenBlock(the_module, NULL, children, 0); + expressions[191] = BinaryenBlock(the_module, NULL, children, 0, BinaryenUndefined()); } expressions[192] = BinaryenIf(the_module, expressions[7], expressions[8], expressions[9]); expressions[193] = BinaryenIf(the_module, expressions[10], expressions[11], expressions[0]); @@ -1374,24 +1374,24 @@ int main() { { BinaryenExpressionRef children[] = { expressions[24], expressions[26], expressions[28], expressions[30], expressions[32], expressions[34], expressions[36], expressions[38], expressions[40], expressions[42], expressions[44], expressions[46], expressions[48], expressions[50], expressions[52], expressions[54], expressions[56], expressions[58], expressions[60], expressions[62], expressions[64], expressions[66], expressions[68], expressions[70], expressions[72], expressions[74], expressions[76], expressions[78], expressions[80], expressions[82], expressions[84], expressions[86], expressions[88], expressions[90], expressions[92], expressions[94], expressions[97], expressions[100], expressions[103], expressions[106], expressions[109], expressions[112], expressions[115], expressions[118], expressions[121], expressions[124], expressions[127], expressions[130], expressions[133], expressions[136], expressions[139], expressions[142], expressions[145], expressions[148], expressions[151], expressions[154], expressions[157], expressions[160], expressions[163], expressions[166], expressions[169], expressions[172], expressions[175], expressions[178], expressions[181], expressions[184], expressions[187], expressions[190], expressions[191], expressions[192], expressions[193], expressions[195], expressions[197], expressions[198], expressions[200], expressions[202], expressions[203], expressions[204], expressions[206], expressions[212], expressions[217], expressions[224], expressions[226], expressions[228], expressions[231], expressions[233], expressions[235], expressions[237], expressions[239], expressions[240], expressions[241], expressions[242], expressions[244], expressions[245], expressions[246] }; - expressions[247] = BinaryenBlock(the_module, "the-value", children, 95); + expressions[247] = BinaryenBlock(the_module, "the-value", children, 95, BinaryenUndefined()); } expressions[248] = BinaryenDrop(the_module, expressions[247]); { BinaryenExpressionRef children[] = { expressions[248] }; - expressions[249] = BinaryenBlock(the_module, "the-nothing", children, 1); + expressions[249] = BinaryenBlock(the_module, "the-nothing", children, 1, BinaryenUndefined()); } expressions[250] = BinaryenConst(the_module, BinaryenLiteralInt32(42)); { BinaryenExpressionRef children[] = { expressions[249], expressions[250] }; - expressions[251] = BinaryenBlock(the_module, "the-body", children, 2); + expressions[251] = BinaryenBlock(the_module, "the-body", children, 2, BinaryenUndefined()); } { BinaryenType varTypes[] = { 1 }; functions[0] = BinaryenAddFunction(the_module, "kitchen()sinker", functionTypes[0], varTypes, 1, expressions[251]); } { - BinaryenIndex paramTypes[] = { 1, 4 }; + BinaryenType paramTypes[] = { 1, 4 }; functionTypes[1] = BinaryenAddFunctionType(the_module, "fiF", 3, paramTypes, 2); } BinaryenAddImport(the_module, "an-imported", "module", "base", functionTypes[1]); @@ -1409,7 +1409,7 @@ int main() { BinaryenSetMemory(the_module, 1, 256, "mem", segments, segmentOffsets, segmentSizes, 1); } { - BinaryenIndex paramTypes[] = { 0 }; + BinaryenType paramTypes[] = { 0 }; functionTypes[2] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0); } expressions[253] = BinaryenNop(the_module); @@ -1419,7 +1419,7 @@ int main() { } BinaryenSetStart(the_module, functions[1]); { - BinaryenIndex paramTypes[] = { 0 }; + BinaryenType paramTypes[] = { 0 }; functionTypes[3] = BinaryenAddFunctionType(the_module, NULL, 0, paramTypes, 0); } BinaryenModuleAutoDrop(the_module); @@ -1964,11 +1964,11 @@ int main() { the_module = BinaryenModuleCreate(); expressions[size_t(NULL)] = BinaryenExpressionRef(NULL); { - BinaryenIndex paramTypes[] = { 0 }; + BinaryenType paramTypes[] = { 0 }; functionTypes[0] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0); } { - BinaryenIndex paramTypes[] = { 1 }; + BinaryenType paramTypes[] = { 1 }; functionTypes[1] = BinaryenAddFunctionType(the_module, "vi", 0, paramTypes, 1); } BinaryenAddImport(the_module, "check", "module", "check", functionTypes[1]); @@ -2394,7 +2394,7 @@ int main() { functions[13] = BinaryenAddFunction(the_module, "duffs-device", functionTypes[0], varTypes, 7, expressions[135]); } { - BinaryenIndex paramTypes[] = { 0 }; + BinaryenType paramTypes[] = { 0 }; functionTypes[2] = BinaryenAddFunctionType(the_module, "i", 1, paramTypes, 0); } the_relooper = RelooperCreate(); @@ -2407,7 +2407,7 @@ int main() { expressions[139] = BinaryenReturn(the_module, expressions[138]); { BinaryenExpressionRef children[] = { expressions[137], expressions[139] }; - expressions[140] = BinaryenBlock(the_module, "the-list", children, 2); + expressions[140] = BinaryenBlock(the_module, "the-list", children, 2, BinaryenUndefined()); } relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[140]); expressions[141] = RelooperRenderAndDispose(the_relooper, relooperBlocks[0], 0, the_module); |