Skip to content

Commit ff27062

Browse files
authored
Use emscripten_has_threading_support. NFC (#22709)
This change also fixes a bug in `LIBRARY_DEBUG` where it wasn't handling single line arrow function correctly.
1 parent 6956a0c commit ff27062

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

src/jsifier.mjs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,21 @@ ${argConversions}
284284

285285
// apply LIBRARY_DEBUG if relevant
286286
if (LIBRARY_DEBUG && !isJsOnlySymbol(symbol)) {
287-
snippet = modifyJSFunction(
288-
snippet,
289-
(args, body, async) => `\
287+
snippet = modifyJSFunction(snippet, (args, body, async, oneliner) => {
288+
var run_func;
289+
if (oneliner) {
290+
run_func = `var ret = ${body}`;
291+
} else {
292+
run_func = `var ret = (() => { ${body} })();`;
293+
}
294+
return `\
290295
function(${args}) {
291-
var ret = (() => { if (runtimeDebug) err("[library call:${mangled}: " + Array.prototype.slice.call(arguments).map(prettyPrint) + "]");
292-
${body}
293-
})();
294-
if (runtimeDebug && typeof ret != "undefined") err(" [ return:" + prettyPrint(ret));
296+
if (runtimeDebug) err("[library call:${mangled}: " + Array.prototype.slice.call(arguments).map(prettyPrint) + "]");
297+
${run_func}
298+
if (runtimeDebug) err(" [ return:" + prettyPrint(ret));
295299
return ret;
296-
}`,
297-
);
300+
}`;
301+
});
298302
}
299303

300304
const sig = LibraryManager.library[symbol + '__sig'];

src/library_pthread.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,16 @@ var LibraryPThread = {
690690
__pthread_create_js__noleakcheck: true,
691691
#endif
692692
__pthread_create_js__deps: ['$spawnThread', 'pthread_self', '$pthreadCreateProxied',
693+
'emscripten_has_threading_support',
693694
#if OFFSCREENCANVAS_SUPPORT
694695
'malloc',
695696
#endif
696697
],
697698
__pthread_create_js: (pthread_ptr, attr, startRoutine, arg) => {
698-
if (typeof SharedArrayBuffer == 'undefined') {
699-
err('Current environment does not support SharedArrayBuffer, pthreads are not available!');
699+
if (!_emscripten_has_threading_support()) {
700+
#if ASSERTIONS
701+
dbg('pthread_create: environment does not support SharedArrayBuffer, pthreads are not available');
702+
#endif
700703
return {{{ cDefs.EAGAIN }}};
701704
}
702705
#if PTHREADS_DEBUG

src/runtime_debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ var runtimeDebug = true; // Switch to false at runtime to disable logging at the
171171
var printObjectList = [];
172172

173173
function prettyPrint(arg) {
174-
if (typeof arg == 'undefined') return '!UNDEFINED!';
174+
if (typeof arg == 'undefined') return 'undefined';
175175
if (typeof arg == 'boolean') arg = arg + 0;
176176
if (!arg) return arg;
177177
var index = printObjectList.indexOf(arg);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4951
1+
4911
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10465
1+
10376

test/test_browser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,11 +3847,12 @@ def test_pthread_condition_variable(self):
38473847

38483848
# Test that pthreads are able to do printf.
38493849
@parameterized({
3850-
'': (False,),
3851-
'debug': (True,),
3850+
'': ([],),
3851+
'O3': (['-O3'],),
3852+
'debug': (['-sLIBRARY_DEBUG'],),
38523853
})
3853-
def test_pthread_printf(self, debug):
3854-
self.btest_exit('pthread/test_pthread_printf.c', args=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE', '-sLIBRARY_DEBUG=%d' % debug])
3854+
def test_pthread_printf(self, args):
3855+
self.btest_exit('pthread/test_pthread_printf.c', args=['-pthread', '-sPTHREAD_POOL_SIZE'] + args)
38553856

38563857
# Test that pthreads are able to do cout. Failed due to https://bugzilla.mozilla.org/show_bug.cgi?id=1154858.
38573858
def test_pthread_iostream(self):

0 commit comments

Comments
 (0)