From 2c00956fd1c7219e82b999af15deb1970db3c379 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 7 Mar 2023 15:01:06 -0800 Subject: [PATCH] Mark USE_PTHREADS as legacy. NFC Create a new internal setting called just `PTHREADS` and use that everywhere internally. This allows the old setting to be marked as legacy, but still supported in case existing use JS library code uses it. --- ChangeLog.md | 3 + embuilder.py | 20 +++---- emcc.py | 35 +++++++----- emscripten.py | 4 +- src/jsifier.js | 4 +- src/library.js | 14 ++--- src/library_browser.js | 4 +- src/library_dylink.js | 10 ++-- src/library_fetch.js | 2 +- src/library_html5.js | 108 ++++++++++++++++++------------------ src/library_html5_webgl.js | 18 +++--- src/library_pipefs.js | 4 +- src/library_pthread.js | 8 +-- src/library_pthread_stub.js | 4 +- src/library_sockfs.js | 4 +- src/library_syscall.js | 2 +- src/library_wasi.js | 2 +- src/library_wasm_worker.js | 2 +- src/library_webgl.js | 14 ++--- src/library_webgpu.js | 2 +- src/library_websocket.js | 2 +- src/modules.js | 2 +- src/parseTools.js | 8 +-- src/postamble.js | 6 +- src/postamble_minimal.js | 16 +++--- src/preamble.js | 30 +++++----- src/preamble_minimal.js | 6 +- src/proxyWorker.js | 10 ++-- src/runtime_debug.js | 2 +- src/runtime_init_memory.js | 6 +- src/settings.js | 8 +-- src/settings_internal.js | 3 + src/shell.js | 14 ++--- src/shell_minimal.js | 10 ++-- test/test_other.py | 1 + tools/deps_info.py | 4 +- tools/feature_matrix.py | 2 +- tools/ports/harfbuzz.py | 6 +- tools/ports/icu.py | 6 +- tools/ports/libpng.py | 6 +- tools/ports/regal.py | 6 +- tools/ports/sdl2.py | 8 +-- tools/ports/sqlite3.py | 6 +- tools/settings.py | 1 + tools/system_libs.py | 2 +- 45 files changed, 219 insertions(+), 216 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 8d696a22a96d6..c97d1efc2d169 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works. 3.1.33 (in development) ----------------------- +- The prefered way to enable pthread is now to just the the standard `-pthread` + flag. The `-sUSE_PTHREADS` setting still works but is marked a legacy and + will generte a warning in `-sSTRICT` mode. - Initial support for C++20 modules. We have added a very simple test in form of `other.test_cpp_module`. (#) - Removed `sys/sysctl.h` compatibility header. We don't implement the function diff --git a/embuilder.py b/embuilder.py index 7e2178ffad55d..488dd9ff50dc9 100755 --- a/embuilder.py +++ b/embuilder.py @@ -122,28 +122,22 @@ def get_help(): @contextmanager def get_port_variant(name): + args = [] if name in ports.port_variants: - name, extra_settings = ports.port_variants[name] - old_settings = settings.dict().copy() - for key, value in extra_settings.items(): - setattr(settings, key, value) - else: - old_settings = None + name, args = ports.port_variants[name] - yield name + yield name, args - if old_settings: - settings.dict().update(old_settings) def clear_port(port_name): - with get_port_variant(port_name) as port_name: - ports.clear_port(port_name, settings) + with get_port_variant(port_name) as port_name, args: + ports.clear_port(port_name, args) def build_port(port_name): - with get_port_variant(port_name) as port_name: - ports.build_port(port_name, settings) + with get_port_variant(port_name) as port_name, args: + ports.build_port(port_name, args) def get_system_tasks(): diff --git a/emcc.py b/emcc.py index 28cd5249ea651..0f411944f8669 100755 --- a/emcc.py +++ b/emcc.py @@ -380,7 +380,7 @@ def setup_environment_settings(): settings.ENVIRONMENT_MAY_BE_WORKER = \ not settings.ENVIRONMENT or \ 'worker' in environments or \ - (settings.ENVIRONMENT_MAY_BE_NODE and settings.USE_PTHREADS) + (settings.ENVIRONMENT_MAY_BE_NODE and settings.PTHREADS) if not settings.ENVIRONMENT_MAY_BE_WORKER and settings.PROXY_TO_WORKER: exit_with_error('If you specify --proxy-to-worker and specify a "-sENVIRONMENT=" directive, it must include "worker" as a target! (Try e.g. -sENVIRONMENT=web,worker)') @@ -1595,11 +1595,14 @@ def phase_setup(options, state, newargs): if settings.MAIN_MODULE or settings.SIDE_MODULE: settings.RELOCATABLE = 1 + if 'USE_PTHREADS' in user_settings: + settings.PTHREADS = settings.USE_PTHREADS + # Pthreads and Wasm Workers require targeting shared Wasm memory (SAB). - if settings.USE_PTHREADS or settings.WASM_WORKERS: + if settings.PTHREADS or settings.WASM_WORKERS: settings.SHARED_MEMORY = 1 - if settings.USE_PTHREADS and '-pthread' not in newargs: + if settings.PTHREADS and '-pthread' not in newargs: newargs += ['-pthread'] elif settings.SHARED_MEMORY: if '-matomics' not in newargs: @@ -1751,7 +1754,7 @@ def include_and_export(name): if not settings.EXPORT_ES6 and settings.EXPORT_NAME == 'Module': exit_with_error('pthreads + MODULARIZE currently require you to set -sEXPORT_NAME=Something (see settings.js) to Something != Module, so that the .worker.js file can work') - # MODULARIZE+USE_PTHREADS mode requires extra exports out to Module so that worker.js + # MODULARIZE+PTHREADS mode requires extra exports out to Module so that worker.js # can access them: # general threading variables: @@ -2099,7 +2102,7 @@ def phase_linker_setup(options, state, newargs): '$mergeLibSymbols', ] - if settings.USE_PTHREADS: + if settings.PTHREADS: settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += [ '$registerTLSInit', ] @@ -2210,7 +2213,7 @@ def phase_linker_setup(options, state, newargs): # HTML output creates a singleton instance, and it does so without the # Promise. However, in Pthreads mode the Promise is used for worker # creation. - if settings.MINIMAL_RUNTIME and options.oformat == OFormat.HTML and not settings.USE_PTHREADS: + if settings.MINIMAL_RUNTIME and options.oformat == OFormat.HTML and not settings.PTHREADS: settings.EXPORT_READY_PROMISE = 0 if settings.LEGACY_VM_SUPPORT: @@ -2327,7 +2330,7 @@ def phase_linker_setup(options, state, newargs): if settings.FETCH and final_suffix in EXECUTABLE_ENDINGS: state.forced_stdlibs.append('libfetch') settings.JS_LIBRARIES.append((0, 'library_fetch.js')) - if settings.USE_PTHREADS: + if settings.PTHREADS: settings.FETCH_WORKER_FILE = unsuffixed_basename(target) + '.fetch.js' if settings.DEMANGLE_SUPPORT: @@ -2397,7 +2400,7 @@ def phase_linker_setup(options, state, newargs): # overrides that. default_setting('ABORTING_MALLOC', 0) - if settings.USE_PTHREADS: + if settings.PTHREADS: setup_pthreads(target) settings.JS_LIBRARIES.append((0, 'library_pthread.js')) if settings.PROXY_TO_PTHREAD: @@ -2629,7 +2632,7 @@ def check_memory_setting(setting): # are based on experimentation with different tests/programs under asan and # lsan. settings.INITIAL_MEMORY += 50 * 1024 * 1024 - if settings.USE_PTHREADS: + if settings.PTHREADS: settings.INITIAL_MEMORY += 50 * 1024 * 1024 if settings.USE_OFFSET_CONVERTER and settings.WASM2JS: @@ -3175,7 +3178,7 @@ def phase_final_emitting(options, state, target, wasm_target, memfile): # write_file(final_js, src) target_dir = os.path.dirname(os.path.abspath(target)) - if settings.USE_PTHREADS: + if settings.PTHREADS: worker_output = os.path.join(target_dir, settings.PTHREAD_WORKER_FILE) contents = shared.read_and_preprocess(utils.path_from_root('src/worker.js'), expand_macros=True) write_file(worker_output, contents) @@ -3576,9 +3579,11 @@ def consume_arg_file(): options.output_eol = '\n' else: exit_with_error(f'Invalid value "{style}" to --output_eol!') - # Record USE_PTHREADS setting because it controls whether --shared-memory is passed to lld + # Record PTHREADS setting because it controls whether --shared-memory is passed to lld elif arg == '-pthread': - settings_changes.append('USE_PTHREADS=1') + settings.PTHREADS = 1 + # Also set the legacy setting name, in case use JS code depends on it. + settings.USE_PTHREADS = 1 elif arg == '-pthreads': exit_with_error('unrecognized command-line option ‘-pthreads’; did you mean ‘-pthread’?') elif arg in ('-fno-diagnostics-color', '-fdiagnostics-color=never'): @@ -3706,7 +3711,7 @@ def phase_binaryen(target, options, wasm_target): # adds some >>> 0 things, while growth will replace a HEAP8 with a call to # a method to get the heap, and that call would not be recognized by the # unsigning pass - if settings.USE_PTHREADS and settings.ALLOW_MEMORY_GROWTH: + if settings.PTHREADS and settings.ALLOW_MEMORY_GROWTH: with ToolchainProfiler.profile_block('apply_wasm_memory_growth'): final_js = building.apply_wasm_memory_growth(final_js) @@ -3880,7 +3885,7 @@ def modularize(): 'capture_module_function_for_audio_worklet': 'globalThis.AudioWorkletModule = Module;' if settings.AUDIO_WORKLET and settings.MODULARIZE else '' } - if settings.MINIMAL_RUNTIME and not settings.USE_PTHREADS: + if settings.MINIMAL_RUNTIME and not settings.PTHREADS: # Single threaded MINIMAL_RUNTIME programs do not need access to # document.currentScript, so a simple export declaration is enough. src = 'var %s=%s' % (settings.EXPORT_NAME, src) @@ -3888,7 +3893,7 @@ def modularize(): script_url_node = '' # When MODULARIZE this JS may be executed later, # after document.currentScript is gone, so we save it. - # In EXPORT_ES6 + USE_PTHREADS the 'thread' is actually an ES6 module webworker running in strict mode, + # In EXPORT_ES6 + PTHREADS the 'thread' is actually an ES6 module webworker running in strict mode, # so doesn't have access to 'document'. In this case use 'import.meta' instead. if settings.EXPORT_ES6 and settings.USE_ES6_IMPORT_META: script_url = 'import.meta.url' diff --git a/emscripten.py b/emscripten.py index f345eb0f89745..7bcf128704451 100644 --- a/emscripten.py +++ b/emscripten.py @@ -144,7 +144,7 @@ def update_settings_glue(wasm_file, metadata): if settings.ASYNCIFY == 2: settings.BINARYEN_FEATURES += ['--enable-reference-types'] - if settings.USE_PTHREADS: + if settings.PTHREADS: assert '--enable-threads' in settings.BINARYEN_FEATURES if settings.MEMORY64: assert '--enable-memory64' in settings.BINARYEN_FEATURES @@ -625,7 +625,7 @@ def add_standard_wasm_imports(send_items_map): if settings.IMPORTED_MEMORY: memory_import = 'wasmMemory' - if settings.MODULARIZE and settings.USE_PTHREADS: + if settings.MODULARIZE and settings.PTHREADS: # Pthreads assign wasmMemory in their worker startup. In MODULARIZE mode, they cannot assign inside the # Module scope, so lookup via Module as well. memory_import += " || Module['wasmMemory']" diff --git a/src/jsifier.js b/src/jsifier.js index 09023bfb6af40..01faabd03da42 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -159,7 +159,7 @@ function ${name}(${args}) { throw new Error(`Invalid proxyingMode ${symbol}__proxy: '${proxyingMode}' specified!`); } const sync = proxyingMode === 'sync'; - if (USE_PTHREADS) { + if (PTHREADS) { snippet = modifyFunction(snippet, (name, args, body) => ` function ${name}(${args}) { if (ENVIRONMENT_IS_PTHREAD) @@ -489,7 +489,7 @@ function ${name}(${args}) { print(indentify(item.JS || '', 2)); } - if (USE_PTHREADS) { + if (PTHREADS) { print('\n // proxiedFunctionTable specifies the list of functions that can be called either synchronously or asynchronously from other threads in postMessage()d or internally queued events. This way a pthread in a Worker can synchronously access e.g. the DOM on the main thread.'); print('\nvar proxiedFunctionTable = [' + proxiedFunctionTable.join() + '];\n'); } diff --git a/src/library.js b/src/library.js index d94985330cc7a..91098b9d1de6a 100644 --- a/src/library.js +++ b/src/library.js @@ -70,7 +70,7 @@ mergeInto(LibraryManager.library, { checkUnflushedContent(); #endif // ASSERTIONS && !EXIT_RUNTIME -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) { // implict exit can never happen on a pthread #if ASSERTIONS @@ -89,7 +89,7 @@ mergeInto(LibraryManager.library, { #if PTHREADS_DEBUG err('main thread called exit: keepRuntimeAlive=' + keepRuntimeAlive() + ' (counter=' + runtimeKeepaliveCounter + ')'); #endif // PTHREADS_DEBUG -#endif // USE_PTHREADS +#endif // PTHREADS #if EXIT_RUNTIME if (!keepRuntimeAlive()) { @@ -2357,7 +2357,7 @@ mergeInto(LibraryManager.library, { " };\n" + "} else " + #endif -#if USE_PTHREADS && !AUDIO_WORKLET +#if PTHREADS && !AUDIO_WORKLET // Pthreads need their clocks synchronized to the execution of the main thread, so, when using them, // make sure to adjust all timings to the respective time origins. "_emscripten_get_now = () => performance.timeOrigin + performance.now();\n", @@ -2371,7 +2371,7 @@ mergeInto(LibraryManager.library, { // AudioWorkletGlobalScope does not have performance.now() (https://github.com/WebAudio/web-audio-api/issues/2527), so if building with // Audio Worklets enabled, do a dynamic check for its presence. "if (typeof performance != 'undefined' && performance.now) {\n" + -#if USE_PTHREADS +#if PTHREADS " _emscripten_get_now = () => performance.timeOrigin + performance.now();\n" + #else " _emscripten_get_now = () => performance.now();\n" + @@ -3044,7 +3044,7 @@ mergeInto(LibraryManager.library, { $runMainThreadEmAsm__sig: 'iippi', $runMainThreadEmAsm: function(code, sigPtr, argbuf, sync) { var args = readEmAsmArgs(sigPtr, argbuf); -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) { // EM_ASM functions are variadic, receiving the actual arguments as a buffer // in memory. the last parameter (argBuf) points to that data. We need to @@ -3564,7 +3564,7 @@ mergeInto(LibraryManager.library, { }, $maybeExit__deps: ['exit', '$handleException', -#if USE_PTHREADS +#if PTHREADS '_emscripten_thread_exit', #endif ], @@ -3582,7 +3582,7 @@ mergeInto(LibraryManager.library, { dbg('maybeExit: calling exit() implicitly after user callback completed: ' + EXITSTATUS); #endif try { -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) __emscripten_thread_exit(EXITSTATUS); else #endif diff --git a/src/library_browser.js b/src/library_browser.js index a8160844ded6b..60ce955f6ce9c 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -846,7 +846,7 @@ var LibraryBrowser = { onload = {{{ makeDynCall('v', 'onload') }}}; onerror = {{{ makeDynCall('v', 'onerror') }}}; -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) { err('emscripten_async_load_script("' + UTF8ToString(url) + '") failed, emscripten_async_load_script is currently not available in pthreads!'); return onerror ? onerror() : undefined; @@ -1049,7 +1049,7 @@ var LibraryBrowser = { GL.newRenderingFrameStarted(); #endif -#if USE_PTHREADS && OFFSCREEN_FRAMEBUFFER && GL_SUPPORT_EXPLICIT_SWAP_CONTROL +#if PTHREADS && OFFSCREEN_FRAMEBUFFER && GL_SUPPORT_EXPLICIT_SWAP_CONTROL // If the current GL context is a proxied regular WebGL context, and was initialized with implicit swap mode on the main thread, and we are on the parent thread, // perform the swap on behalf of the user. if (typeof GL != 'undefined' && GL.currentContext && GL.currentContextIsProxied) { diff --git a/src/library_dylink.js b/src/library_dylink.js index 4f9292b74c414..f114fd5fa77ab 100644 --- a/src/library_dylink.js +++ b/src/library_dylink.js @@ -719,7 +719,7 @@ var LibraryDylink = { } #if STACK_OVERFLOW_CHECK >= 2 if (moduleExports['__set_stack_limits']) { -#if USE_PTHREADS +#if PTHREADS // When we are on an uninitialized pthread we delay calling // __set_stack_limits until $setDylinkStackLimits. if (!ENVIRONMENT_IS_PTHREAD || runtimeInitialized) @@ -762,7 +762,7 @@ var LibraryDylink = { #endif // initialize the module -#if USE_PTHREADS +#if PTHREADS // Only one thread should call __wasm_call_ctors, but all threads need // to call _emscripten_tls_init registerTLSInit(moduleExports['_emscripten_tls_init'], instance.exports, metadata) @@ -788,7 +788,7 @@ var LibraryDylink = { __ATINIT__.push(init); } } -#if USE_PTHREADS +#if PTHREADS } #endif return moduleExports; @@ -826,8 +826,8 @@ var LibraryDylink = { return loadModule(); }, -#if STACK_OVERFLOW_CHECK >= 2 && USE_PTHREADS - // With USE_PTHREADS we load libraries before we are running a pthread and +#if STACK_OVERFLOW_CHECK >= 2 && PTHREADS + // With PTHREADS we load libraries before we are running a pthread and // therefore before we have a stack. Instead we delay calling // `__set_stack_limits` until we start running a thread. We also need to call // this again for each new thread that the runs on a worker (since each thread diff --git a/src/library_fetch.js b/src/library_fetch.js index 07b909f5994f0..44492af5a814e 100644 --- a/src/library_fetch.js +++ b/src/library_fetch.js @@ -7,7 +7,7 @@ #include Fetch.js var LibraryFetch = { -#if USE_PTHREADS +#if PTHREADS $Fetch__postset: 'if (!ENVIRONMENT_IS_PTHREAD) Fetch.staticInit();', #else $Fetch__postset: 'Fetch.staticInit();', diff --git a/src/library_html5.js b/src/library_html5.js index df1e4a4ac92cb..68138ef5d8271 100644 --- a/src/library_html5.js +++ b/src/library_html5.js @@ -187,7 +187,7 @@ var LibraryHTML5 = { } }, -#if USE_PTHREADS +#if PTHREADS queueEventHandlerOnThread_iiii: function(targetThread, eventHandlerFunc, eventTypeId, eventData, userData) { withStackSave(function() { var varargs = stackAlloc(12); @@ -199,7 +199,7 @@ var LibraryHTML5 = { }, #endif -#if USE_PTHREADS +#if PTHREADS getTargetThreadForEventCallback: function(targetThread) { switch (targetThread) { case {{{ cDefine('EM_CALLBACK_THREAD_CONTEXT_MAIN_RUNTIME_THREAD') }}}: return 0; // The event callback for the current event should be called on the main browser thread. (0 == don't proxy) @@ -237,7 +237,7 @@ var LibraryHTML5 = { $registerKeyEventCallback__deps: ['$JSEvents', '$findEventTarget'], $registerKeyEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.keyEvent) JSEvents.keyEvent = _malloc( {{{ C_STRUCTS.EmscriptenKeyboardEvent.__size__ }}} ); @@ -247,7 +247,7 @@ var LibraryHTML5 = { assert(e); #endif -#if USE_PTHREADS +#if PTHREADS var keyEventData = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenKeyboardEvent.__size__ }}} ) : JSEvents.keyEvent; // This allocated block is passed as satellite data to the proxied function call, so the call frees up the data block when done. #else var keyEventData = JSEvents.keyEvent; @@ -270,7 +270,7 @@ var LibraryHTML5 = { stringToUTF8(e.char || '', keyEventData + {{{ C_STRUCTS.EmscriptenKeyboardEvent.charValue }}}, {{{ cDefine('EM_HTML5_SHORT_STRING_LEN_BYTES') }}}); stringToUTF8(e.locale || '', keyEventData + {{{ C_STRUCTS.EmscriptenKeyboardEvent.locale }}}, {{{ cDefine('EM_HTML5_SHORT_STRING_LEN_BYTES') }}}); -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, keyEventData, userData); else #endif @@ -302,7 +302,7 @@ var LibraryHTML5 = { // Users can also add more special event targets, basically by just doing something like // specialHTMLTargets["!canvas"] = Module.canvas; // (that will let !canvas map to the canvas held in Module.canvas). -#if ENVIRONMENT_MAY_BE_WORKER || ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL || USE_PTHREADS +#if ENVIRONMENT_MAY_BE_WORKER || ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL || PTHREADS $specialHTMLTargets: "[0, typeof document != 'undefined' ? document : 0, typeof window != 'undefined' ? window : 0]", #else $specialHTMLTargets: "[0, document, window]", @@ -349,7 +349,7 @@ var LibraryHTML5 = { // OffscreenCanvas that we can find. || (target == 'canvas' && Object.keys(GL.offscreenCanvases)[0]) // If that is not found either, query via the regular DOM selector. -#if USE_PTHREADS +#if PTHREADS || (typeof document != 'undefined' && document.querySelector(target)); #else || document.querySelector(target); @@ -508,7 +508,7 @@ var LibraryHTML5 = { $registerMouseEventCallback__deps: ['$JSEvents', '$fillMouseEventData', '$findEventTarget'], $registerMouseEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.mouseEvent) JSEvents.mouseEvent = _malloc( {{{ C_STRUCTS.EmscriptenMouseEvent.__size__ }}} ); @@ -518,7 +518,7 @@ var LibraryHTML5 = { // TODO: Make this access thread safe, or this could update live while app is reading it. fillMouseEventData(JSEvents.mouseEvent, e, target); -#if USE_PTHREADS +#if PTHREADS if (targetThread) { var mouseEventData = _malloc( {{{ C_STRUCTS.EmscriptenMouseEvent.__size__ }}} ); // This allocated block is passed as satellite data to the proxied function call, so the call frees up the data block when done. fillMouseEventData(mouseEventData, e, target); @@ -631,14 +631,14 @@ var LibraryHTML5 = { $registerWheelEventCallback__deps: ['$JSEvents', '$fillMouseEventData', '$findEventTarget'], $registerWheelEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.wheelEvent) JSEvents.wheelEvent = _malloc( {{{ C_STRUCTS.EmscriptenWheelEvent.__size__ }}} ); // The DOM Level 3 events spec event 'wheel' var wheelHandlerFunc = function(e = event) { -#if USE_PTHREADS +#if PTHREADS var wheelEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenWheelEvent.__size__ }}} ) : JSEvents.wheelEvent; // This allocated block is passed as satellite data to the proxied function call, so the call frees up the data block when done. #else var wheelEvent = JSEvents.wheelEvent; @@ -648,7 +648,7 @@ var LibraryHTML5 = { {{{ makeSetValue('wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaY, 'e["deltaY"]', 'double') }}}; {{{ makeSetValue('wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaZ, 'e["deltaZ"]', 'double') }}}; {{{ makeSetValue('wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaMode, 'e["deltaMode"]', 'i32') }}}; -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, wheelEvent, userData); else #endif @@ -708,7 +708,7 @@ var LibraryHTML5 = { $registerUiEventCallback__deps: ['$JSEvents', '$findEventTarget'], $registerUiEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.uiEvent) JSEvents.uiEvent = _malloc( {{{ C_STRUCTS.EmscriptenUiEvent.__size__ }}} ); @@ -737,7 +737,7 @@ var LibraryHTML5 = { // During a page unload 'body' can be null, with "Cannot read property 'clientWidth' of null" being thrown return; } -#if USE_PTHREADS +#if PTHREADS var uiEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenUiEvent.__size__ }}} ) : JSEvents.uiEvent; #else var uiEvent = JSEvents.uiEvent; @@ -751,7 +751,7 @@ var LibraryHTML5 = { {{{ makeSetValue('uiEvent', C_STRUCTS.EmscriptenUiEvent.windowOuterHeight, 'outerHeight', 'i32') }}}; {{{ makeSetValue('uiEvent', C_STRUCTS.EmscriptenUiEvent.scrollTop, 'pageXOffset', 'i32') }}}; {{{ makeSetValue('uiEvent', C_STRUCTS.EmscriptenUiEvent.scrollLeft, 'pageYOffset', 'i32') }}}; -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, uiEvent, userData); else #endif @@ -786,7 +786,7 @@ var LibraryHTML5 = { $registerFocusEventCallback__deps: ['$JSEvents', '$findEventTarget'], $registerFocusEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.focusEvent) JSEvents.focusEvent = _malloc( {{{ C_STRUCTS.EmscriptenFocusEvent.__size__ }}} ); @@ -795,7 +795,7 @@ var LibraryHTML5 = { var nodeName = JSEvents.getNodeNameForTarget(e.target); var id = e.target.id ? e.target.id : ''; -#if USE_PTHREADS +#if PTHREADS var focusEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenFocusEvent.__size__ }}} ) : JSEvents.focusEvent; #else var focusEvent = JSEvents.focusEvent; @@ -803,7 +803,7 @@ var LibraryHTML5 = { stringToUTF8(nodeName, focusEvent + {{{ C_STRUCTS.EmscriptenFocusEvent.nodeName }}}, {{{ cDefine('EM_HTML5_LONG_STRING_LEN_BYTES') }}}); stringToUTF8(id, focusEvent + {{{ C_STRUCTS.EmscriptenFocusEvent.id }}}, {{{ cDefine('EM_HTML5_LONG_STRING_LEN_BYTES') }}}); -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, focusEvent, userData); else #endif @@ -862,7 +862,7 @@ var LibraryHTML5 = { $registerDeviceOrientationEventCallback__deps: ['$JSEvents', '$fillDeviceOrientationEventData', '$findEventTarget'], $registerDeviceOrientationEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.deviceOrientationEvent) JSEvents.deviceOrientationEvent = _malloc( {{{ C_STRUCTS.EmscriptenDeviceOrientationEvent.__size__ }}} ); @@ -870,7 +870,7 @@ var LibraryHTML5 = { var deviceOrientationEventHandlerFunc = function(e = event) { fillDeviceOrientationEventData(JSEvents.deviceOrientationEvent, e, target); // TODO: Thread-safety with respect to emscripten_get_deviceorientation_status() -#if USE_PTHREADS +#if PTHREADS if (targetThread) { var deviceOrientationEvent = _malloc( {{{ C_STRUCTS.EmscriptenDeviceOrientationEvent.__size__ }}} ); fillDeviceOrientationEventData(deviceOrientationEvent, e, target); @@ -935,7 +935,7 @@ var LibraryHTML5 = { $registerDeviceMotionEventCallback__deps: ['$JSEvents', '$fillDeviceMotionEventData', '$findEventTarget'], $registerDeviceMotionEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.deviceMotionEvent) JSEvents.deviceMotionEvent = _malloc( {{{ C_STRUCTS.EmscriptenDeviceMotionEvent.__size__ }}} ); @@ -943,7 +943,7 @@ var LibraryHTML5 = { var deviceMotionEventHandlerFunc = function(e = event) { fillDeviceMotionEventData(JSEvents.deviceMotionEvent, e, target); // TODO: Thread-safety with respect to emscripten_get_devicemotion_status() -#if USE_PTHREADS +#if PTHREADS if (targetThread) { var deviceMotionEvent = _malloc( {{{ C_STRUCTS.EmscriptenDeviceMotionEvent.__size__ }}} ); fillDeviceMotionEventData(deviceMotionEvent, e, target); @@ -1005,13 +1005,13 @@ var LibraryHTML5 = { $registerOrientationChangeEventCallback__deps: ['$JSEvents', '$fillOrientationChangeEventData', '$findEventTarget'], $registerOrientationChangeEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.orientationChangeEvent) JSEvents.orientationChangeEvent = _malloc( {{{ C_STRUCTS.EmscriptenOrientationChangeEvent.__size__ }}} ); var orientationChangeEventHandlerFunc = function(e = event) { -#if USE_PTHREADS +#if PTHREADS var orientationChangeEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenOrientationChangeEvent.__size__ }}} ) : JSEvents.orientationChangeEvent; #else var orientationChangeEvent = JSEvents.orientationChangeEvent; @@ -1019,7 +1019,7 @@ var LibraryHTML5 = { fillOrientationChangeEventData(orientationChangeEvent); -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, orientationChangeEvent, userData); else #endif @@ -1129,13 +1129,13 @@ var LibraryHTML5 = { $registerFullscreenChangeEventCallback__deps: ['$JSEvents', '$fillFullscreenChangeEventData', '$findEventTarget'], $registerFullscreenChangeEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.fullscreenChangeEvent) JSEvents.fullscreenChangeEvent = _malloc( {{{ C_STRUCTS.EmscriptenFullscreenChangeEvent.__size__ }}} ); var fullscreenChangeEventhandlerFunc = function(e = event) { -#if USE_PTHREADS +#if PTHREADS var fullscreenChangeEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenFullscreenChangeEvent.__size__ }}} ) : JSEvents.fullscreenChangeEvent; #else var fullscreenChangeEvent = JSEvents.fullscreenChangeEvent; @@ -1143,7 +1143,7 @@ var LibraryHTML5 = { fillFullscreenChangeEventData(fullscreenChangeEvent); -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, fullscreenChangeEvent, userData); else #endif @@ -1228,7 +1228,7 @@ var LibraryHTML5 = { currentFullscreenStrategy = strategy; if (strategy.canvasResizedCallback) { -#if USE_PTHREADS +#if PTHREADS if (strategy.canvasResizedCallbackTargetThread) JSEvents.queueEventHandlerOnThread_iiii(strategy.canvasResizedCallbackTargetThread, strategy.canvasResizedCallback, {{{ cDefine('EMSCRIPTEN_EVENT_CANVASRESIZED') }}}, 0, strategy.canvasResizedCallbackUserData); else #endif @@ -1380,7 +1380,7 @@ var LibraryHTML5 = { if (canvas.GLctxObject) canvas.GLctxObject.GLctx.viewport(0, 0, oldWidth, oldHeight); if (currentFullscreenStrategy.canvasResizedCallback) { -#if USE_PTHREADS +#if PTHREADS if (currentFullscreenStrategy.canvasResizedCallbackTargetThread) JSEvents.queueEventHandlerOnThread_iiii(currentFullscreenStrategy.canvasResizedCallbackTargetThread, currentFullscreenStrategy.canvasResizedCallback, {{{ cDefine('EMSCRIPTEN_EVENT_CANVASRESIZED') }}}, 0, currentFullscreenStrategy.canvasResizedCallbackUserData); else #endif @@ -1508,7 +1508,7 @@ var LibraryHTML5 = { } if (!inCenteredWithoutScalingFullscreenMode && currentFullscreenStrategy.canvasResizedCallback) { -#if USE_PTHREADS +#if PTHREADS if (currentFullscreenStrategy.canvasResizedCallbackTargetThread) JSEvents.queueEventHandlerOnThread_iiii(currentFullscreenStrategy.canvasResizedCallbackTargetThread, currentFullscreenStrategy.canvasResizedCallback, {{{ cDefine('EMSCRIPTEN_EVENT_CANVASRESIZED') }}}, 0, currentFullscreenStrategy.canvasResizedCallbackUserData); else #endif @@ -1585,7 +1585,7 @@ var LibraryHTML5 = { #if HTML5_SUPPORT_DEFERRING_USER_SENSITIVE_REQUESTS deferUntilInEventHandler: deferUntilInEventHandler, #endif -#if USE_PTHREADS +#if PTHREADS canvasResizedCallbackTargetThread: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.canvasResizedCallbackTargetThread, 'i32') }}}, #endif canvasResizedCallback: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.canvasResizedCallback, 'i32') }}}, @@ -1611,7 +1611,7 @@ var LibraryHTML5 = { filteringMode: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.filteringMode, 'i32') }}}, canvasResizedCallback: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.canvasResizedCallback, 'i32') }}}, canvasResizedCallbackUserData: {{{ makeGetValue('fullscreenStrategy', C_STRUCTS.EmscriptenFullscreenStrategy.canvasResizedCallbackUserData, 'i32') }}}, -#if USE_PTHREADS +#if PTHREADS canvasResizedCallbackTargetThread: JSEvents.getTargetThreadForEventCallback(), #endif target: target, @@ -1631,7 +1631,7 @@ var LibraryHTML5 = { restoreHiddenElements(hiddenElements); removeEventListener('resize', softFullscreenResizeWebGLRenderTarget); if (strategy.canvasResizedCallback) { -#if USE_PTHREADS +#if PTHREADS if (strategy.canvasResizedCallbackTargetThread) JSEvents.queueEventHandlerOnThread_iiii(strategy.canvasResizedCallbackTargetThread, strategy.canvasResizedCallback, {{{ cDefine('EMSCRIPTEN_EVENT_CANVASRESIZED') }}}, 0, strategy.canvasResizedCallbackUserData); else #endif @@ -1645,7 +1645,7 @@ var LibraryHTML5 = { // Inform the caller that the canvas size has changed. if (strategy.canvasResizedCallback) { -#if USE_PTHREADS +#if PTHREADS if (strategy.canvasResizedCallbackTargetThread) JSEvents.queueEventHandlerOnThread_iiii(strategy.canvasResizedCallbackTargetThread, strategy.canvasResizedCallback, {{{ cDefine('EMSCRIPTEN_EVENT_CANVASRESIZED') }}}, 0, strategy.canvasResizedCallbackUserData); else #endif @@ -1714,20 +1714,20 @@ var LibraryHTML5 = { $registerPointerlockChangeEventCallback__deps: ['$JSEvents', '$fillPointerlockChangeEventData', '$findEventTarget'], $registerPointerlockChangeEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.pointerlockChangeEvent) JSEvents.pointerlockChangeEvent = _malloc( {{{ C_STRUCTS.EmscriptenPointerlockChangeEvent.__size__ }}} ); var pointerlockChangeEventHandlerFunc = function(e = event) { -#if USE_PTHREADS +#if PTHREADS var pointerlockChangeEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenPointerlockChangeEvent.__size__ }}} ) : JSEvents.pointerlockChangeEvent; #else var pointerlockChangeEvent = JSEvents.pointerlockChangeEvent; #endif fillPointerlockChangeEventData(pointerlockChangeEvent); -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, pointerlockChangeEvent, userData); else #endif @@ -1769,12 +1769,12 @@ var LibraryHTML5 = { $registerPointerlockErrorEventCallback__deps: ['$JSEvents', '$findEventTarget', '$specialHTMLTargets'], $registerPointerlockErrorEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif var pointerlockErrorEventHandlerFunc = function(e = event) { -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, 0, userData); else #endif @@ -1967,13 +1967,13 @@ var LibraryHTML5 = { $registerVisibilityChangeEventCallback__deps: ['$JSEvents', '$fillVisibilityChangeEventData', '$findEventTarget'], $registerVisibilityChangeEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.visibilityChangeEvent) JSEvents.visibilityChangeEvent = _malloc( {{{ C_STRUCTS.EmscriptenVisibilityChangeEvent.__size__ }}} ); var visibilityChangeEventHandlerFunc = function(e = event) { -#if USE_PTHREADS +#if PTHREADS var visibilityChangeEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenVisibilityChangeEvent.__size__ }}} ) : JSEvents.visibilityChangeEvent; #else var visibilityChangeEvent = JSEvents.visibilityChangeEvent; @@ -1981,7 +1981,7 @@ var LibraryHTML5 = { fillVisibilityChangeEventData(visibilityChangeEvent); -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, visibilityChangeEvent, userData); else #endif @@ -2024,7 +2024,7 @@ var LibraryHTML5 = { $registerTouchEventCallback__deps: ['$JSEvents', '$findEventTarget', '$getBoundingClientRect'], $registerTouchEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.touchEvent) JSEvents.touchEvent = _malloc( {{{ C_STRUCTS.EmscriptenTouchEvent.__size__ }}} ); @@ -2058,7 +2058,7 @@ var LibraryHTML5 = { touches[e.targetTouches[i].identifier].onTarget = 1; } -#if USE_PTHREADS +#if PTHREADS var touchEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenTouchEvent.__size__ }}} ) : JSEvents.touchEvent; #else var touchEvent = JSEvents.touchEvent; @@ -2101,7 +2101,7 @@ var LibraryHTML5 = { } {{{ makeSetValue('touchEvent', C_STRUCTS.EmscriptenTouchEvent.numTouches, 'numTouches', 'i32') }}}; -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, touchEvent, userData); else #endif @@ -2186,20 +2186,20 @@ var LibraryHTML5 = { $registerGamepadEventCallback__deps: ['$JSEvents', '$fillGamepadEventData', '$findEventTarget'], $registerGamepadEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.gamepadEvent) JSEvents.gamepadEvent = _malloc( {{{ C_STRUCTS.EmscriptenGamepadEvent.__size__ }}} ); var gamepadEventHandlerFunc = function(e = event) { -#if USE_PTHREADS +#if PTHREADS var gamepadEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenGamepadEvent.__size__ }}} ) : JSEvents.gamepadEvent; #else var gamepadEvent = JSEvents.gamepadEvent; #endif fillGamepadEventData(gamepadEvent, e["gamepad"]); -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, gamepadEvent, userData); else #endif @@ -2327,20 +2327,20 @@ var LibraryHTML5 = { $registerBatteryEventCallback__deps: ['$JSEvents', '$fillBatteryEventData', '$battery', '$findEventTarget', 'malloc'], $registerBatteryEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif if (!JSEvents.batteryEvent) JSEvents.batteryEvent = _malloc( {{{ C_STRUCTS.EmscriptenBatteryEvent.__size__ }}} ); var batteryEventHandlerFunc = function(e = event) { -#if USE_PTHREADS +#if PTHREADS var batteryEvent = targetThread ? _malloc( {{{ C_STRUCTS.EmscriptenBatteryEvent.__size__ }}} ) : JSEvents.batteryEvent; #else var batteryEvent = JSEvents.batteryEvent; #endif fillBatteryEventData(batteryEvent, battery()); -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, batteryEvent, userData); else #endif @@ -2384,7 +2384,7 @@ var LibraryHTML5 = { return {{{ cDefine('EMSCRIPTEN_RESULT_SUCCESS') }}}; }, -#if USE_PTHREADS +#if PTHREADS emscripten_set_canvas_element_size_calling_thread__deps: [ '$JSEvents', #if OFFSCREENCANVAS_SUPPORT @@ -2540,7 +2540,7 @@ var LibraryHTML5 = { } }, -#if USE_PTHREADS +#if PTHREADS emscripten_get_canvas_element_size_calling_thread__deps: ['$JSEvents', '$findCanvasEventTarget'], emscripten_get_canvas_element_size_calling_thread: function(target, width, height) { var canvas = findCanvasEventTarget(target); diff --git a/src/library_html5_webgl.js b/src/library_html5_webgl.js index e83389ae41a75..d2bce7fdcd2a0 100644 --- a/src/library_html5_webgl.js +++ b/src/library_html5_webgl.js @@ -37,7 +37,7 @@ var LibraryHtml5WebGL = { HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}}>>2)] = HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}}>>2)] = 1; -#if USE_PTHREADS +#if PTHREADS // Default context initialization state (user can override): // - if main thread is creating the context, default to the context not being shared between threads - enabling sharing has performance overhead, because it forces the context to be OffscreenCanvas or OffscreenFramebuffer. // - if a web worker is creating the context, default to using OffscreenCanvas if available, or proxying via Offscreen Framebuffer if not @@ -47,7 +47,7 @@ var LibraryHtml5WebGL = { _emscripten_webgl_power_preferences: "['default', 'low-power', 'high-performance']", -#if USE_PTHREADS && OFFSCREEN_FRAMEBUFFER +#if PTHREADS && OFFSCREEN_FRAMEBUFFER // In offscreen framebuffer mode, we implement a proxied version of the // emscripten_webgl_create_context() function in JS. emscripten_webgl_create_context_proxied__proxy: 'sync', @@ -79,7 +79,7 @@ var LibraryHtml5WebGL = { #if LibraryManager.has('library_webgl.js') '$GL', #endif -#if USE_PTHREADS && OFFSCREEN_FRAMEBUFFER +#if PTHREADS && OFFSCREEN_FRAMEBUFFER 'emscripten_webgl_create_context_proxied', #endif '$JSEvents', '_emscripten_webgl_power_preferences', '$findEventTarget', '$findCanvasEventTarget'], @@ -115,7 +115,7 @@ var LibraryHtml5WebGL = { var targetStr = UTF8ToString(target); #endif -#if USE_PTHREADS && OFFSCREEN_FRAMEBUFFER +#if PTHREADS && OFFSCREEN_FRAMEBUFFER // Create a WebGL context that is proxied to main thread if canvas was not found on worker, or if explicitly requested to do so. if (ENVIRONMENT_IS_PTHREAD) { if (contextAttributes.proxyContextToMainThread === {{{ cDefine('EMSCRIPTEN_WEBGL_CONTEXT_PROXY_ALWAYS') }}} || @@ -214,7 +214,7 @@ var LibraryHtml5WebGL = { var contextHandle = GL.createContext(canvas, contextAttributes); return contextHandle; }, -#if USE_PTHREADS && OFFSCREEN_FRAMEBUFFER +#if PTHREADS && OFFSCREEN_FRAMEBUFFER // Runs on the calling thread, proxies if needed. emscripten_webgl_make_context_current_calling_thread__sig: 'ii', emscripten_webgl_make_context_current_calling_thread: function(contextHandle) { @@ -327,7 +327,7 @@ var LibraryHtml5WebGL = { GL.deleteContext(contextHandle); }, -#if USE_PTHREADS +#if PTHREADS // Special function that will be invoked on the thread calling emscripten_webgl_destroy_context(), before routing // the call over to the target thread. emscripten_webgl_destroy_context_before_on_calling_thread__deps: ['emscripten_webgl_get_current_context', 'emscripten_webgl_make_context_current'], @@ -409,7 +409,7 @@ var LibraryHtml5WebGL = { _registerWebGlEventCallback__deps: ['$JSEvents', '$findEventTarget'], _registerWebGlEventCallback: function(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) { -#if USE_PTHREADS +#if PTHREADS targetThread = JSEvents.getTargetThreadForEventCallback(targetThread); #endif @@ -418,7 +418,7 @@ var LibraryHtml5WebGL = { #endif var webGlEventHandlerFunc = function(e = event) { -#if USE_PTHREADS +#if PTHREADS if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, 0, userData); else #endif @@ -566,7 +566,7 @@ var LibraryHtml5WebGL = { }, }; -#if USE_PTHREADS +#if PTHREADS // Process 'sync_on_webgl_context_handle_thread' and 'sync_on_current_webgl_context_thread' pseudo-proxying modes // to appropriate proxying mechanism, either proxying on-demand, unconditionally, or never, depending on build modes. // 'sync_on_webgl_context_handle_thread' is used for function signatures that take a HTML5 WebGL context handle diff --git a/src/library_pipefs.js b/src/library_pipefs.js index c679c7e2c0f59..d2f3cac46b4fb 100644 --- a/src/library_pipefs.js +++ b/src/library_pipefs.js @@ -94,7 +94,7 @@ mergeInto(LibraryManager.library, { currentLength += bucket.offset - bucket.roffset; } -#if USE_PTHREADS +#if PTHREADS assert(buffer instanceof ArrayBuffer || buffer instanceof SharedArrayBuffer || ArrayBuffer.isView(buffer)); #else assert(buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer)); @@ -151,7 +151,7 @@ mergeInto(LibraryManager.library, { write: function (stream, buffer, offset, length, position /* ignored */) { var pipe = stream.node.pipe; -#if USE_PTHREADS +#if PTHREADS assert(buffer instanceof ArrayBuffer || buffer instanceof SharedArrayBuffer || ArrayBuffer.isView(buffer)); #else assert(buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer)); diff --git a/src/library_pthread.js b/src/library_pthread.js index c7095badc5203..b3e5df5d8471f 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -7,14 +7,14 @@ * features within this file (ES2020). */ -#if !USE_PTHREADS -#error "Internal error! USE_PTHREADS should be enabled when including library_pthread.js." +#if !PTHREADS +#error "Internal error! PTHREADS should be enabled when including library_pthread.js." #endif #if !SHARED_MEMORY #error "Internal error! SHARED_MEMORY should be enabled when including library_pthread.js." #endif -#if USE_PTHREADS == 2 -#error "USE_PTHREADS=2 is no longer supported" +#if PTHREADS == 2 +#error "PTHREADS=2 is no longer supported" #endif #if BUILD_AS_WORKER #error "pthreads + BUILD_AS_WORKER require separate modes that don't work together, see https://github.com/emscripten-core/emscripten/issues/8854" diff --git a/src/library_pthread_stub.js b/src/library_pthread_stub.js index b18ef09eafb77..a7a10f6bb361f 100644 --- a/src/library_pthread_stub.js +++ b/src/library_pthread_stub.js @@ -4,8 +4,8 @@ * SPDX-License-Identifier: MIT */ -#if USE_PTHREADS -#error "Internal error! USE_PTHREADS should not be enabled when including library_pthread_stub.js." +#if PTHREADS +#error "Internal error! PTHREADS should not be enabled when including library_pthread_stub.js." #endif #if STANDALONE_WASM && SHARED_MEMORY #error "STANDALONE_WASM does not support shared memories yet" diff --git a/src/library_sockfs.js b/src/library_sockfs.js index 829ec54c6dc4d..44e653a6fa0a3 100644 --- a/src/library_sockfs.js +++ b/src/library_sockfs.js @@ -619,7 +619,7 @@ mergeInto(LibraryManager.library, { } var data; -#if USE_PTHREADS +#if PTHREADS // WebSockets .send() does not allow passing a SharedArrayBuffer, so clone the portion of the SharedArrayBuffer as a regular // ArrayBuffer that we want to send. if (buffer instanceof SharedArrayBuffer) { @@ -627,7 +627,7 @@ mergeInto(LibraryManager.library, { } else { #endif data = buffer.slice(offset, offset + length); -#if USE_PTHREADS +#if PTHREADS } #endif diff --git a/src/library_syscall.js b/src/library_syscall.js index 677ad46bf4461..9899e9e34dd81 100644 --- a/src/library_syscall.js +++ b/src/library_syscall.js @@ -1087,7 +1087,7 @@ function wrapSyscallFunction(x, library, isWasi) { library[x] = eval('(' + t + ')'); if (!library[x + '__deps']) library[x + '__deps'] = []; library[x + '__deps'].push('$SYSCALLS'); -#if USE_PTHREADS +#if PTHREADS // Most syscalls need to happen on the main JS thread (e.g. because the // filesystem is in JS and on that thread). Proxy synchronously to there. // There are some exceptions, syscalls that we know are ok to just run in diff --git a/src/library_wasi.js b/src/library_wasi.js index 5c3484b0346d0..3aff37ecfbb4c 100644 --- a/src/library_wasi.js +++ b/src/library_wasi.js @@ -26,7 +26,7 @@ var WasiLibrary = { #endif EXITSTATUS = code; if (!keepRuntimeAlive()) { -#if USE_PTHREADS +#if PTHREADS PThread.terminateAllThreads(); #endif #if expectToReceiveOnModule('onExit') diff --git a/src/library_wasm_worker.js b/src/library_wasm_worker.js index ef2d6df293950..e43a75eefdb06 100644 --- a/src/library_wasm_worker.js +++ b/src/library_wasm_worker.js @@ -70,7 +70,7 @@ mergeInto(LibraryManager.library, { #endif // Run the C side Worker initialization for stack and TLS. _emscripten_wasm_worker_initialize(m['sb'], m['sz']); -#if USE_PTHREADS +#if PTHREADS // Record that this Wasm Worker supports synchronous blocking in emscripten_futex_wake(). ___set_thread_state(/*thread_ptr=*/0, /*is_main_thread=*/0, /*is_runtime_thread=*/0, /*supports_wait=*/0); #endif diff --git a/src/library_webgl.js b/src/library_webgl.js index 48b4d044035c7..5caa0b9ba819e 100644 --- a/src/library_webgl.js +++ b/src/library_webgl.js @@ -150,7 +150,7 @@ var LibraryGL = { #if GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS // If GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS is enabled, GL.initExtensions() will call to initialize these. $GL__deps: [ -#if USE_PTHREADS +#if PTHREADS 'malloc', // Needed by registerContext #endif #if MIN_WEBGL_VERSION == 1 @@ -195,7 +195,7 @@ var LibraryGL = { textures: [], shaders: [], vaos: [], -#if USE_PTHREADS // with pthreads a context is a location in memory with some synchronized data between threads +#if PTHREADS // with pthreads a context is a location in memory with some synchronized data between threads contexts: {}, #else // without pthreads, it's just an integer ID contexts: [], @@ -972,7 +972,7 @@ var LibraryGL = { #endif registerContext: function(ctx, webGLContextAttributes) { -#if USE_PTHREADS +#if PTHREADS // with pthreads a context is a location in memory with some synchronized data between threads var handle = _malloc(8); #if GL_ASSERTIONS @@ -982,10 +982,10 @@ var LibraryGL = { {{{ makeSetValue('handle', 0, 'webGLContextAttributes.explicitSwapControl', 'i32')}}}; // explicitSwapControl #endif {{{ makeSetValue('handle', 4, '_pthread_self()', 'i32')}}}; // the thread pointer of the thread that owns the control of the context -#else // USE_PTHREADS +#else // PTHREADS // without pthreads a context is just an integer ID var handle = GL.getNewId(GL.contexts); -#endif // USE_PTHREADS +#endif // PTHREADS var context = { handle: handle, @@ -1051,7 +1051,7 @@ var LibraryGL = { makeContextCurrent: function(contextHandle) { #if GL_DEBUG if (contextHandle && !GL.contexts[contextHandle]) { -#if USE_PTHREADS +#if PTHREADS dbg('GL.makeContextCurrent() failed! WebGL context ' + contextHandle + ' does not exist, or was created on another thread!'); #else dbg('GL.makeContextCurrent() failed! WebGL context ' + contextHandle + ' does not exist!'); @@ -1072,7 +1072,7 @@ var LibraryGL = { if (GL.currentContext === GL.contexts[contextHandle]) GL.currentContext = null; if (typeof JSEvents == 'object') JSEvents.removeAllHandlersOnTarget(GL.contexts[contextHandle].GLctx.canvas); // Release all JS event handlers on the DOM element that the GL context is associated with since the context is now deleted. if (GL.contexts[contextHandle] && GL.contexts[contextHandle].GLctx.canvas) GL.contexts[contextHandle].GLctx.canvas.GLctxObject = undefined; // Make sure the canvas object no longer refers to the context object so there are no GC surprises. -#if USE_PTHREADS +#if PTHREADS _free(GL.contexts[contextHandle].handle); #endif GL.contexts[contextHandle] = null; diff --git a/src/library_webgpu.js b/src/library_webgpu.js index c4ab3d4341550..f0a3b5237e505 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js @@ -1440,7 +1440,7 @@ var LibraryWebGPU = { case {{{ gpu.SType.ShaderModuleSPIRVDescriptor }}}: { var count = {{{ gpu.makeGetU32('nextInChainPtr', C_STRUCTS.WGPUShaderModuleSPIRVDescriptor.codeSize) }}}; var start = {{{ makeGetValue('nextInChainPtr', C_STRUCTS.WGPUShaderModuleSPIRVDescriptor.code, '*') }}}; -#if USE_PTHREADS +#if PTHREADS // Chrome can't currently handle a SharedArrayBuffer view here, so make a copy. desc["code"] = HEAPU32.slice(start >> 2, (start >> 2) + count); #else diff --git a/src/library_websocket.js b/src/library_websocket.js index 59ac24e0c1b00..7e56602085387 100644 --- a/src/library_websocket.js +++ b/src/library_websocket.js @@ -363,7 +363,7 @@ var LibraryWebSocket = { dbg('emscripten_websocket_send_binary(socketId='+socketId+',binaryData='+binaryData+ ',dataLength='+dataLength+'), ' + s); #endif -#if USE_PTHREADS +#if PTHREADS // TODO: This is temporary to cast a shared Uint8Array to a non-shared Uint8Array. This could be removed if WebSocket API is improved // to allow passing in views to SharedArrayBuffers socket.send(new Uint8Array({{{ makeHEAPView('U8', 'binaryData', 'binaryData+dataLength') }}})); diff --git a/src/modules.js b/src/modules.js index bd97f32d97416..91ecbbb13f29b 100644 --- a/src/modules.js +++ b/src/modules.js @@ -365,7 +365,7 @@ function exportRuntime() { // them via EXPORTED_RUNTIME_METHODS for backwards compat. runtimeElements = runtimeElements.concat(WASM_SYSTEM_EXPORTS); - if (USE_PTHREADS && ALLOW_MEMORY_GROWTH) { + if (PTHREADS && ALLOW_MEMORY_GROWTH) { runtimeElements = runtimeElements.concat([ 'GROWABLE_HEAP_I8', 'GROWABLE_HEAP_U8', diff --git a/src/parseTools.js b/src/parseTools.js index 931963072f0c7..49d569ad55290 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -705,11 +705,11 @@ function modifyFunction(text, func) { } function runIfMainThread(text) { - if (WASM_WORKERS && USE_PTHREADS) { + if (WASM_WORKERS && PTHREADS) { return 'if (!ENVIRONMENT_IS_WASM_WORKER && !ENVIRONMENT_IS_PTHREAD) { ' + text + ' }'; } else if (WASM_WORKERS) { return 'if (!ENVIRONMENT_IS_WASM_WORKER) { ' + text + ' }'; - } else if (USE_PTHREADS) { + } else if (PTHREADS) { return 'if (!ENVIRONMENT_IS_PTHREAD) { ' + text + ' }'; } else { return text; @@ -936,7 +936,7 @@ function makeMalloc(source, param) { // We skip this completely in MINIMAL_RUNTIME and also in builds that // don't ever need to exit the runtime. function runtimeKeepalivePush() { - if (MINIMAL_RUNTIME || (EXIT_RUNTIME == 0 && USE_PTHREADS == 0)) return ''; + if (MINIMAL_RUNTIME || (EXIT_RUNTIME == 0 && PTHREADS == 0)) return ''; return 'runtimeKeepalivePush();'; } @@ -945,7 +945,7 @@ function runtimeKeepalivePush() { // We skip this completely in MINIMAL_RUNTIME and also in builds that // don't ever need to exit the runtime. function runtimeKeepalivePop() { - if (MINIMAL_RUNTIME || (EXIT_RUNTIME == 0 && USE_PTHREADS == 0)) return ''; + if (MINIMAL_RUNTIME || (EXIT_RUNTIME == 0 && PTHREADS == 0)) return ''; return 'runtimeKeepalivePop();'; } diff --git a/src/postamble.js b/src/postamble.js index b5bb3b4feec20..12adf97cf2e96 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -117,7 +117,7 @@ function stackCheckInit() { // This is normally called automatically during __wasm_call_ctors but need to // get these values before even running any of the ctors so we call it redundantly // here. -#if ASSERTIONS && USE_PTHREADS +#if ASSERTIONS && PTHREADS // See $establishStackSpace for the equivelent code that runs on a thread assert(!ENVIRONMENT_IS_PTHREAD); #endif @@ -152,7 +152,7 @@ function run() { } #if STACK_OVERFLOW_CHECK -#if USE_PTHREADS +#if PTHREADS if (!ENVIRONMENT_IS_PTHREAD) #endif stackCheckInit(); @@ -188,7 +188,7 @@ function run() { } #endif -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) { #if MODULARIZE // The promise resolve function typically gets called as part of the execution diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 7a4bdbb805149..396d955b43ef6 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -26,7 +26,7 @@ function run() { #if EXIT_RUNTIME callRuntimeCallbacks(__ATEXIT__); <<< ATEXITS >>> -#if USE_PTHREADS +#if PTHREADS PThread.terminateAllThreads(); #endif @@ -53,7 +53,7 @@ function initRuntime(asm) { runtimeInitialized = true; #endif -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) { // Export needed variables that worker.js needs to Module. Module['HEAPU32'] = HEAPU32; @@ -76,7 +76,7 @@ function initRuntime(asm) { #endif #endif -#if USE_PTHREADS +#if PTHREADS PThread.tlsInitFunctions.push(asm['_emscripten_tls_init']); #endif @@ -104,7 +104,7 @@ var imports = { var asm; #endif -#if USE_PTHREADS +#if PTHREADS var wasmModule; #endif @@ -151,14 +151,14 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) { // output.module objects. But if Module['wasm'] is an already compiled // WebAssembly module, then output is the WebAssembly instance itself. // Depending on the build mode, Module['wasm'] can mean a different thing. -#if MINIMAL_RUNTIME_STREAMING_WASM_COMPILATION || MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION || USE_PTHREADS +#if MINIMAL_RUNTIME_STREAMING_WASM_COMPILATION || MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION || PTHREADS // https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming // Firefox 52 added Wasm support, but only Firefox 58 added compileStreaming & // instantiateStreaming. // Chrome 57 added Wasm support, but only Chrome 61 added compileStreaming & // instantiateStreaming. // Node.js and Safari do not support compileStreaming or instantiateStreaming. -#if MIN_FIREFOX_VERSION < 58 || MIN_CHROME_VERSION < 61 || ENVIRONMENT_MAY_BE_NODE || MIN_SAFARI_VERSION != TARGET_NOT_SUPPORTED || USE_PTHREADS +#if MIN_FIREFOX_VERSION < 58 || MIN_CHROME_VERSION < 61 || ENVIRONMENT_MAY_BE_NODE || MIN_SAFARI_VERSION != TARGET_NOT_SUPPORTED || PTHREADS // In pthreads, Module['wasm'] is an already compiled WebAssembly.Module. In // that case, 'output' is a WebAssembly.Instance. // In main thread, Module['wasm'] is either a typed array or a fetch stream. @@ -176,7 +176,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) { #endif #if USE_OFFSET_CONVERTER -#if USE_PTHREADS +#if PTHREADS if (!ENVIRONMENT_IS_PTHREAD) #endif wasmOffsetConverter = new WasmOffsetConverter(Module['wasm'], output.module); @@ -227,7 +227,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) { #endif initRuntime(asm); -#if USE_PTHREADS +#if PTHREADS // Export Wasm module for pthread creation to access. wasmModule = output.module || Module['wasm']; PThread.loadWasmModuleToAllWorkers(ready); diff --git a/src/preamble.js b/src/preamble.js index f0ffc881719fa..69b09341662ec 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -202,7 +202,7 @@ function keepRuntimeAlive() { } function preRun() { -#if ASSERTIONS && USE_PTHREADS +#if ASSERTIONS && PTHREADS assert(!ENVIRONMENT_IS_PTHREAD); // PThreads reuse the runtime from the main thread. #endif #if expectToReceiveOnModule('preRun') @@ -226,7 +226,7 @@ function initRuntime() { if (ENVIRONMENT_IS_WASM_WORKER) return __wasm_worker_initializeRuntime(); #endif -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) return; #endif @@ -252,7 +252,7 @@ function preMain() { #if STACK_OVERFLOW_CHECK checkStackCookie(); #endif -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) return; // PThreads reuse the runtime from the main thread. #endif <<< ATMAINS >>> @@ -275,7 +275,7 @@ function exitRuntime() { #if STACK_OVERFLOW_CHECK checkStackCookie(); #endif -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) return; // PThreads reuse the runtime from the main thread. #endif #if !STANDALONE_WASM @@ -283,7 +283,7 @@ function exitRuntime() { #endif callRuntimeCallbacks(__ATEXIT__); <<< ATEXITS >>> -#if USE_PTHREADS +#if PTHREADS PThread.terminateAllThreads(); #endif runtimeExited = true; @@ -294,7 +294,7 @@ function postRun() { #if STACK_OVERFLOW_CHECK checkStackCookie(); #endif -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) return; // PThreads reuse the runtime from the main thread. #endif @@ -991,7 +991,7 @@ function createWasm() { Module['asm'] = exports; -#if USE_PTHREADS +#if PTHREADS #if MAIN_MODULE registerTLSInit(Module['asm']['_emscripten_tls_init'], instance.exports, metadata); #else @@ -1046,16 +1046,16 @@ function createWasm() { exportAsmFunctions(exports); #endif -#if USE_PTHREADS || WASM_WORKERS +#if PTHREADS || WASM_WORKERS // We now have the Wasm module loaded up, keep a reference to the compiled module so we can post it to the workers. wasmModule = module; #endif -#if USE_PTHREADS +#if PTHREADS PThread.loadWasmModuleToAllWorkers(() => removeRunDependency('wasm-instantiate')); #else // singlethreaded build: removeRunDependency('wasm-instantiate'); -#endif // ~USE_PTHREADS +#endif // ~PTHREADS return exports; } @@ -1085,7 +1085,7 @@ function createWasm() { receiveInstance(result['instance'], result['module']); #else // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line. - // When the regression is fixed, can restore the above USE_PTHREADS-enabled path. + // When the regression is fixed, can restore the above PTHREADS-enabled path. receiveInstance(result['instance']); #endif } @@ -1098,7 +1098,7 @@ function createWasm() { // Also pthreads and wasm workers initialize the wasm instance through this path. if (Module['instantiateWasm']) { #if USE_OFFSET_CONVERTER -#if ASSERTIONS && USE_PTHREADS +#if ASSERTIONS && PTHREADS if (ENVIRONMENT_IS_PTHREAD) { assert(Module['wasmOffsetData'], 'wasmOffsetData not found on Module object'); } @@ -1106,7 +1106,7 @@ function createWasm() { wasmOffsetConverter = resetPrototype(WasmOffsetConverter, Module['wasmOffsetData']); #endif #if LOAD_SOURCE_MAP -#if ASSERTIONS && USE_PTHREADS +#if ASSERTIONS && PTHREADS if (ENVIRONMENT_IS_PTHREAD) { assert(Module['wasmSourceMapData'], 'wasmSourceMapData not found on Module object'); } @@ -1143,7 +1143,7 @@ function createWasm() { return {}; // no exports yet; we'll fill them in later #else var result = instantiateSync(wasmBinaryFile, info); -#if USE_PTHREADS || MAIN_MODULE +#if PTHREADS || MAIN_MODULE return receiveInstance(result[0], result[1]); #else // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, @@ -1173,7 +1173,7 @@ function getCompilerSetting(name) { var memoryInitializer = <<< MEM_INITIALIZER >>>; function runMemoryInitializer() { -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) return; #endif if (!isDataURI(memoryInitializer)) { diff --git a/src/preamble_minimal.js b/src/preamble_minimal.js index bedb131ac189f..dc6ea52ad9e6b 100644 --- a/src/preamble_minimal.js +++ b/src/preamble_minimal.js @@ -94,7 +94,7 @@ function updateMemoryViews() { } #if IMPORTED_MEMORY -#if USE_PTHREADS +#if PTHREADS if (!ENVIRONMENT_IS_PTHREAD) { #endif wasmMemory = @@ -110,14 +110,14 @@ if (!ENVIRONMENT_IS_PTHREAD) { , 'shared': true #endif }); -#if USE_PTHREADS +#if PTHREADS } #if MODULARIZE else { wasmMemory = Module['wasmMemory']; } #endif // MODULARIZE -#endif // USE_PTHREADS +#endif // PTHREADS updateMemoryViews(); #endif // IMPORTED_MEMORY diff --git a/src/proxyWorker.js b/src/proxyWorker.js index ec92a51b6edf7..c70aaa90b1d2a 100644 --- a/src/proxyWorker.js +++ b/src/proxyWorker.js @@ -382,12 +382,12 @@ Module['postMainLoop'] = function() { // Wait to start running until we receive some info from the client -#if USE_PTHREADS +#if PTHREADS if (!ENVIRONMENT_IS_PTHREAD) { #endif addRunDependency('gl-prefetch'); addRunDependency('worker-init'); -#if USE_PTHREADS +#if PTHREADS } #endif @@ -484,7 +484,7 @@ function onMessageFromMainEmscriptenThread(message) { screen.height = Module.canvas.height_ = message.data.height; Module.canvas.boundingClientRect = message.data.boundingClientRect; document.URL = message.data.URL; -#if USE_PTHREADS +#if PTHREADS currentScriptUrl = message.data.currentScriptUrl; #endif window.fireEvent({ type: 'load' }); @@ -507,11 +507,11 @@ function onMessageFromMainEmscriptenThread(message) { } }; -#if USE_PTHREADS +#if PTHREADS if (!ENVIRONMENT_IS_PTHREAD) { #endif onmessage = onMessageFromMainEmscriptenThread; -#if USE_PTHREADS +#if PTHREADS } #endif diff --git a/src/runtime_debug.js b/src/runtime_debug.js index 89cebe542b536..96663a21659d9 100644 --- a/src/runtime_debug.js +++ b/src/runtime_debug.js @@ -129,7 +129,7 @@ function prettyPrint(arg) { #if ASSERTIONS || RUNTIME_DEBUG // Used by XXXXX_DEBUG settings to output debug messages. function dbg(text) { -#if ENVIRONMENT_MAY_BE_NODE && USE_PTHREADS +#if ENVIRONMENT_MAY_BE_NODE && PTHREADS // Avoid using the console for debugging in multi-threaded node applications // See https://github.com/emscripten-core/emscripten/issues/14804 if (ENVIRONMENT_IS_NODE) { diff --git a/src/runtime_init_memory.js b/src/runtime_init_memory.js index 4b87f96c02322..a22027493755c 100644 --- a/src/runtime_init_memory.js +++ b/src/runtime_init_memory.js @@ -15,11 +15,11 @@ assert(INITIAL_MEMORY >= {{{STACK_SIZE}}}, 'INITIAL_MEMORY should be larger than // check for full engine support (use string 'subarray' to avoid closure compiler confusion) -#if USE_PTHREADS +#if PTHREADS if (ENVIRONMENT_IS_PTHREAD) { wasmMemory = Module['wasmMemory']; } else { -#endif // USE_PTHREADS +#endif // PTHREADS #if expectToReceiveOnModule('wasmMemory') if (Module['wasmMemory']) { @@ -55,7 +55,7 @@ if (ENVIRONMENT_IS_PTHREAD) { #endif } -#if USE_PTHREADS +#if PTHREADS } #endif diff --git a/src/settings.js b/src/settings.js index 957ace4412cc6..1a9c436f0a3f9 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1516,11 +1516,6 @@ var USE_SQLITE3 = false; // [compile+link] - affects user code at compile and system libraries at link. var SHARED_MEMORY = false; -// If true, enables support for pthreads. This implies SHARED_MEMORY. -// This setting is equivalent to `-pthread`, which should be preferred. -// [compile+link] - affects user code at compile and system libraries at link. -var USE_PTHREADS = false; - // If true, enables support for Wasm Workers. Wasm Workers enable applications // to create threads using a lightweight web-specific API that builds on top // of Wasm SharedArrayBuffer + Atomics API. @@ -2015,7 +2010,7 @@ var PURE_WASI = false; // it to JavaScript. // Use of the following settings will enable this settings since they // depend on being able to define the memory in JavaScript: -// - USE_PTHREADS +// - -pthread // - RELOCATABLE // - ASYNCIFY_LAZY_LOAD_CODE // - WASM2JS (WASM=0) @@ -2178,4 +2173,5 @@ var LEGACY_SETTINGS = [ ['SHELL_FILE', [''], 'No longer supported'], ['LLD_REPORT_UNDEFINED', [1], 'Disabling is no longer supported'], ['MEM_INIT_METHOD', [0], 'No longer supported'], + ['USE_PTHREADS', [0, 1], 'No longer needed. Use -pthread instead'], ]; diff --git a/src/settings_internal.js b/src/settings_internal.js index 65a26eb8e44d3..fb0271691c580 100644 --- a/src/settings_internal.js +++ b/src/settings_internal.js @@ -256,3 +256,6 @@ var HAVE_EM_ASM = true; var PRE_JS_FILES = []; var POST_JS_FILES = []; + +// Set when -pthread / -sPTHREADS is passed +var PTHREADS = false; diff --git a/src/shell.js b/src/shell.js index 33763dec4c4b5..5375e1daa5799 100644 --- a/src/shell.js +++ b/src/shell.js @@ -98,7 +98,7 @@ var ENVIRONMENT_IS_AUDIO_WORKLET = typeof AudioWorkletGlobalScope !== 'undefined #if ENVIRONMENT && !ENVIRONMENT.includes(',') var ENVIRONMENT_IS_WEB = {{{ ENVIRONMENT === 'web' }}}; -#if USE_PTHREADS && ENVIRONMENT_MAY_BE_NODE +#if PTHREADS && ENVIRONMENT_MAY_BE_NODE // node+pthreads always supports workers; detect which we are at runtime var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function'; #else @@ -126,7 +126,7 @@ if (Module['ENVIRONMENT']) { } #endif -#if USE_PTHREADS +#if PTHREADS // Three configurations we can be running in: // 1) We could be the application main() thread running in the main JS UI thread. (ENVIRONMENT_IS_WORKER == false and ENVIRONMENT_IS_PTHREAD == false) // 2) We could be the application main() thread proxied to worker. (with Emscripten -sPROXY_TO_WORKER) (ENVIRONMENT_IS_WORKER == true, ENVIRONMENT_IS_PTHREAD == false) @@ -262,7 +262,7 @@ if (ENVIRONMENT_IS_NODE) { Module['inspect'] = function () { return '[Emscripten Module object]'; }; -#if USE_PTHREADS +#if PTHREADS let nodeWorkerThreads; try { nodeWorkerThreads = require('worker_threads'); @@ -408,7 +408,7 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { // Differentiate the Web Worker from the Node Worker case, as reading must // be done differently. -#if USE_PTHREADS && ENVIRONMENT_MAY_BE_NODE +#if PTHREADS && ENVIRONMENT_MAY_BE_NODE if (!ENVIRONMENT_IS_NODE) #endif { @@ -427,7 +427,7 @@ if (!ENVIRONMENT_IS_AUDIO_WORKLET) #endif // ASSERTIONS } -#if ENVIRONMENT_MAY_BE_NODE && USE_PTHREADS +#if ENVIRONMENT_MAY_BE_NODE && PTHREADS if (ENVIRONMENT_IS_NODE) { // Polyfill the performance object, which emscripten pthreads support // depends on for good timing. @@ -495,14 +495,14 @@ assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has be {{{ makeRemovedFSAssert('NODEFS') }}} #endif -#if USE_PTHREADS +#if PTHREADS assert( #if AUDIO_WORKLET ENVIRONMENT_IS_AUDIO_WORKLET || #endif ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER || ENVIRONMENT_IS_NODE, 'Pthreads do not work in this environment yet (need Web Workers, or an alternative to them)'); #else -#endif // USE_PTHREADS +#endif // PTHREADS #if !ENVIRONMENT_MAY_BE_WEB assert(!ENVIRONMENT_IS_WEB, "web environment detected but not enabled at build time. Add 'web' to `-sENVIRONMENT` to enable."); diff --git a/src/shell_minimal.js b/src/shell_minimal.js index 2729c608d8c67..d019d388ffd6b 100644 --- a/src/shell_minimal.js +++ b/src/shell_minimal.js @@ -56,7 +56,7 @@ var ENVIRONMENT_IS_SHELL = typeof read == 'function'; var ENVIRONMENT_IS_AUDIO_WORKLET = typeof AudioWorkletGlobalScope !== 'undefined'; #endif -#if ASSERTIONS || USE_PTHREADS +#if ASSERTIONS || PTHREADS #if !ENVIRONMENT_MAY_BE_NODE && !ENVIRONMENT_MAY_BE_SHELL var ENVIRONMENT_IS_WEB = true #elif ENVIRONMENT && !ENVIRONMENT.includes(',') @@ -68,7 +68,7 @@ var ENVIRONMENT_IS_WEB = !ENVIRONMENT_IS_SHELL; #else var ENVIRONMENT_IS_WEB = !ENVIRONMENT_IS_NODE; #endif -#endif // ASSERTIONS || USE_PTHREADS +#endif // ASSERTIONS || PTHREADS #if WASM_WORKERS var ENVIRONMENT_IS_WASM_WORKER = Module['$ww']; @@ -138,7 +138,7 @@ function ready() { #elif ASSERTIONS out('ready() called, and INVOKE_RUN=0. The runtime is now ready for you to call run() to invoke application _main(). You can also override ready() in a --pre-js file to get this signal as a callback') #endif -#if USE_PTHREADS +#if PTHREADS // This Worker is now ready to host pthreads, tell the main thread we can proceed. if (ENVIRONMENT_IS_PTHREAD) { startWorker(Module); @@ -157,7 +157,7 @@ function ready() { // refer to Module (if they choose; they can also define Module) {{{ preJS() }}} -#if USE_PTHREADS +#if PTHREADS #if !MODULARIZE // In MODULARIZE mode _scriptDir needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there @@ -175,4 +175,4 @@ var ENVIRONMENT_IS_WORKER = ENVIRONMENT_IS_PTHREAD = typeof importScripts == 'fu #endif var currentScriptUrl = typeof _scriptDir != 'undefined' ? _scriptDir : ((typeof document != 'undefined' && document.currentScript) ? document.currentScript.src : undefined); -#endif // USE_PTHREADS +#endif // PTHREADS diff --git a/test/test_other.py b/test/test_other.py index 8889b251b7017..2373915088648 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -186,6 +186,7 @@ def do_other_test(self, testname, emcc_args=None, **kwargs): def run_on_pty(self, cmd): master, slave = os.openpty() output = [] + print(cmd) try: with env_modify({'TERM': 'xterm-color'}): diff --git a/tools/deps_info.py b/tools/deps_info.py index 8671b86b8795e..34619fa6683d0 100644 --- a/tools/deps_info.py +++ b/tools/deps_info.py @@ -197,11 +197,11 @@ def get_deps_info(): _deps_info['__cxa_find_matching_catch_7'] = ['__cxa_can_catch', 'setTempRet0'] _deps_info['__cxa_find_matching_catch_8'] = ['__cxa_can_catch', 'setTempRet0'] _deps_info['__cxa_find_matching_catch_9'] = ['__cxa_can_catch', 'setTempRet0'] - if settings.USE_PTHREADS and settings.OFFSCREENCANVAS_SUPPORT: + if settings.PTHREADS and settings.OFFSCREENCANVAS_SUPPORT: _deps_info['pthread_create'] = ['malloc'] if settings.FILESYSTEM and settings.SYSCALLS_REQUIRE_FILESYSTEM: _deps_info['mmap'] = ['emscripten_builtin_memalign'] - if settings.USE_PTHREADS: + if settings.PTHREADS: _deps_info['glutCreateWindow'] = ['malloc'] _deps_info['emscripten_webgl_create_context'] = ['malloc'] _deps_info['emscripten_webgl_destroy_context'] = ['free'] diff --git a/tools/feature_matrix.py b/tools/feature_matrix.py index 9530d5df56c26..a20086d21ea4b 100644 --- a/tools/feature_matrix.py +++ b/tools/feature_matrix.py @@ -109,6 +109,6 @@ def enable_feature(feature, reason): def apply_min_browser_versions(): if settings.WASM_BIGINT: enable_feature(Feature.JS_BIGINT_INTEGRATION, 'WASM_BIGINT') - if settings.USE_PTHREADS: + if settings.PTHREADS: enable_feature(Feature.THREADS, 'pthreads') enable_feature(Feature.BULK_MEMORY, 'pthreads') diff --git a/tools/ports/harfbuzz.py b/tools/ports/harfbuzz.py index ad05f9854cc23..7e1012d9aa624 100644 --- a/tools/ports/harfbuzz.py +++ b/tools/ports/harfbuzz.py @@ -10,7 +10,7 @@ HASH = '2e5ab5ad83a0d8801abd3f82a276f776a0ad330edc0ab843f879dd7ad3fd2e0dc0e9a3efbb6c5f2e67d14c0e37f0d9abdb40c5e25d8231a357c0025669f219c3' deps = ['freetype'] -variants = {'harfbuzz-mt': {'USE_PTHREADS': 1}} +variants = {'harfbuzz-mt': ['-pthread']} srcs = ''' hb-aat-layout.cc @@ -76,7 +76,7 @@ def needed(settings): def get_lib_name(settings): - return 'libharfbuzz' + ('-mt' if settings.USE_PTHREADS else '') + '.a' + return 'libharfbuzz' + ('-mt' if settings.PTHREADS else '') + '.a' def get(ports, settings, shared): @@ -124,7 +124,7 @@ def create(final): if settings.RELOCATABLE: cflags.append('-fPIC') - if settings.USE_PTHREADS: + if settings.PTHREADS: cflags.append('-pthread') cflags.append('-DHAVE_PTHREAD') else: diff --git a/tools/ports/icu.py b/tools/ports/icu.py index 3b9bb964f0494..ca0171ba97e09 100644 --- a/tools/ports/icu.py +++ b/tools/ports/icu.py @@ -10,7 +10,7 @@ VERSION = '68_2' HASH = '12c3db5966c234c94e7918fb8acc8bd0838edc36a620f3faa788e7ff27b06f1aa431eb117401026e3963622b9323212f444b735d5c9dd3d0b82d772a4834b993' -variants = {'icu-mt': {'USE_PTHREADS': 1}} +variants = {'icu-mt': {'PTHREADS': 1}} libname_libicu_common = 'libicu_common' libname_libicu_stubdata = 'libicu_stubdata' @@ -22,7 +22,7 @@ def needed(settings): def get_lib_name(base_name, settings): - return base_name + ('-mt' if settings.USE_PTHREADS else '') + '.a' + return base_name + ('-mt' if settings.PTHREADS else '') + '.a' def get(ports, settings, shared): @@ -53,7 +53,7 @@ def build_lib(lib_output, lib_src, other_includes, build_flags): # CXXFLAGS '-std=c++11' ] - if settings.USE_PTHREADS: + if settings.PTHREADS: additional_build_flags.append('-pthread') ports.build_port(lib_src, lib_output, 'icu', includes=other_includes, flags=build_flags + additional_build_flags) diff --git a/tools/ports/libpng.py b/tools/ports/libpng.py index af81e8296946e..1e9c91b3670a6 100644 --- a/tools/ports/libpng.py +++ b/tools/ports/libpng.py @@ -10,7 +10,7 @@ HASH = '2ce2b855af307ca92a6e053f521f5d262c36eb836b4810cb53c809aa3ea2dcc08f834aee0ffd66137768a54397e28e92804534a74abb6fc9f6f3127f14c9c338' deps = ['zlib'] -variants = {'libpng-mt': {'USE_PTHREADS': 1}} +variants = {'libpng-mt': {'PTHREADS': 1}} def needed(settings): @@ -18,7 +18,7 @@ def needed(settings): def get_lib_name(settings): - return 'libpng' + ('-mt' if settings.USE_PTHREADS else '') + '.a' + return 'libpng' + ('-mt' if settings.PTHREADS else '') + '.a' def get(ports, settings, shared): @@ -33,7 +33,7 @@ def create(final): ports.install_headers(source_path) flags = ['-sUSE_ZLIB'] - if settings.USE_PTHREADS: + if settings.PTHREADS: flags += ['-pthread'] ports.build_port(source_path, final, 'libpng', flags=flags, exclude_files=['pngtest'], exclude_dirs=['scripts', 'contrib']) diff --git a/tools/ports/regal.py b/tools/ports/regal.py index a70876001fc29..7b16ea523bc35 100644 --- a/tools/ports/regal.py +++ b/tools/ports/regal.py @@ -9,7 +9,7 @@ TAG = 'version_7' HASH = 'a921dab254f21cf5d397581c5efe58faf147c31527228b4fb34aed75164c736af4b3347092a8d9ec1249160230fa163309a87a20c2b9ceef8554566cc215de9d' -variants = {'regal-mt': {'USE_PTHREADS': 1}} +variants = {'regal-mt': {'PTHREADS': 1}} def needed(settings): @@ -17,7 +17,7 @@ def needed(settings): def get_lib_name(settings): - return 'libregal' + ('-mt' if settings.USE_PTHREADS else '') + '.a' + return 'libregal' + ('-mt' if settings.PTHREADS else '') + '.a' def get(ports, settings, shared): @@ -113,7 +113,7 @@ def create(final): '-Wno-deprecated-register', '-Wno-unused-parameter' ] - if settings.USE_PTHREADS: + if settings.PTHREADS: flags += ['-pthread'] ports.build_port(source_path_src, final, 'regal', srcs=srcs_regal, flags=flags) diff --git a/tools/ports/sdl2.py b/tools/ports/sdl2.py index a0a759366b872..24dd8757195f7 100644 --- a/tools/ports/sdl2.py +++ b/tools/ports/sdl2.py @@ -9,7 +9,7 @@ HASH = 'b178bdc8f7c40271e09a72f639649d1d61953dda4dc12b77437259667b63b961fd3b2c67b0de6fdc5f9f9c80c49bfafd164e4c13715bc1056e550acc8bad5a3c' SUBDIR = 'SDL-' + TAG -variants = {'sdl2-mt': {'USE_PTHREADS': 1}} +variants = {'sdl2-mt': {'PTHREADS': 1}} def needed(settings): @@ -17,7 +17,7 @@ def needed(settings): def get_lib_name(settings): - return 'libSDL2' + ('-mt' if settings.USE_PTHREADS else '') + '.a' + return 'libSDL2' + ('-mt' if settings.PTHREADS else '') + '.a' def get(ports, settings, shared): @@ -64,13 +64,13 @@ def create(final): main/dummy/SDL_dummy_main.c locale/SDL_locale.c locale/emscripten/SDL_syslocale.c misc/SDL_url.c misc/emscripten/SDL_sysurl.c'''.split() thread_srcs = ['SDL_syscond.c', 'SDL_sysmutex.c', 'SDL_syssem.c', 'SDL_systhread.c', 'SDL_systls.c'] - thread_backend = 'generic' if not settings.USE_PTHREADS else 'pthread' + thread_backend = 'generic' if not settings.PTHREADS else 'pthread' srcs += ['thread/%s/%s' % (thread_backend, s) for s in thread_srcs] srcs = [os.path.join(src_dir, 'src', s) for s in srcs] flags = ['-sUSE_SDL=0'] includes = [ports.get_include_dir('SDL2')] - if settings.USE_PTHREADS: + if settings.PTHREADS: flags += ['-pthread'] ports.build_port(src_dir, final, 'sdl2', srcs=srcs, includes=includes, flags=flags) diff --git a/tools/ports/sqlite3.py b/tools/ports/sqlite3.py index 97123e7eb1ef6..dcbb5b5b6020d 100644 --- a/tools/ports/sqlite3.py +++ b/tools/ports/sqlite3.py @@ -12,7 +12,7 @@ VERSION_YEAR = 2022 HASH = 'cbaf4adb3e404d9aa403b34f133c5beca5f641ae1e23f84dbb021da1fb9efdc7c56b5922eb533ae5cb6d26410ac60cb3f026085591bc83ebc1c225aed0cf37ca' -variants = {'sqlite3-mt': {'USE_PTHREADS': 1}} +variants = {'sqlite3-mt': {'PTHREADS': 1}} def needed(settings): @@ -20,7 +20,7 @@ def needed(settings): def get_lib_name(settings): - return 'libsqlite3' + ('-mt' if settings.USE_PTHREADS else '') + '.a' + return 'libsqlite3' + ('-mt' if settings.PTHREADS else '') + '.a' def get(ports, settings, shared): @@ -63,7 +63,7 @@ def create(final): '-DSQLITE_ENABLE_GEOPOLY=1', '-DSQLITE_OMIT_POPEN=1', ] - if settings.USE_PTHREADS: + if settings.PTHREADS: flags += [ '-pthread', '-DSQLITE_THREADSAFE=1', diff --git a/tools/settings.py b/tools/settings.py index fd41dde2410d5..53c016a4067d6 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -55,6 +55,7 @@ # Subset of settings that apply at compile time. # (Keep in sync with [compile] comments in settings.js) COMPILE_TIME_SETTINGS = { + 'PTHREADS', 'MEMORY64', 'INLINING_LIMIT', 'DISABLE_EXCEPTION_CATCHING', diff --git a/tools/system_libs.py b/tools/system_libs.py index 05022c7b5e0f5..8bf9bb24297d5 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -650,7 +650,7 @@ def vary_on(cls): @classmethod def get_default_variation(cls, **kwargs): - return super().get_default_variation(is_mt=settings.USE_PTHREADS, is_ww=settings.WASM_WORKERS and not settings.USE_PTHREADS, **kwargs) + return super().get_default_variation(is_mt=settings.PTHREADS, is_ww=settings.WASM_WORKERS and not settings.PTHREADS, **kwargs) @classmethod def variations(cls):