[WasmFS] Add an async constructor for the OPFS backend

When pthreads are enabled, the existing OPFS backend constructor synchronously
waits for a worker thread to start up and become ready to receive work. Since
the process of starting the worker thread requires the main thread to return to
its event loop, calling the constructor on the main thread would deadlock. The
previous workaround was to simply not call the constructor on the main thread.

As a more elegant solution, add an async version of the constructor that returns
an em_promise_t that will be fulfilled with the backend handle once the worker
thread has started up. This async constructor can be safely called from the main
thread; the promise simply won't be fulfilled until the main thread gets a
chance to return to its event loop.

Internally, the new constructor works by having the worker thread asynchronously
proxy a task back to the constructing thread when it is ready to receive work.
The task resolves a promise on the constructing thread, which leads to the
user-visible promise getting fulfilled with the value of the backend handle.

Add tests using the new constructor in a fully asynchronous way using pthreads
or JSPI as well as tests that use JSPI to await the result of the constructor
with and without pthreads enabled.
6 files changed
tree: cf9485e0ba83941f4d26a12162ec45533ab4a539
  1. .circleci/
  2. .github/
  3. cmake/
  4. docs/
  5. media/
  6. site/
  7. src/
  8. system/
  9. test/
  10. third_party/
  11. tools/
  12. .clang-format
  13. .coveragerc
  14. .editorconfig
  15. .eslintrc.yml
  16. .flake8
  17. .git-blame-ignore-revs
  18. .gitattributes
  19. .gitignore
  20. .gitmodules
  21. .mypy.ini
  22. .prettierrc.yml
  23. .style.yapf
  24. AUTHORS
  25. ChangeLog.md
  26. CONTRIBUTING.md
  27. em++
  28. em++.bat
  29. em++.py
  30. em-config
  31. em-config.bat
  32. em-config.py
  33. emar
  34. emar.bat
  35. emar.py
  36. embuilder
  37. embuilder.bat
  38. embuilder.py
  39. emcc
  40. emcc.bat
  41. emcc.py
  42. emcmake
  43. emcmake.bat
  44. emcmake.py
  45. emconfigure
  46. emconfigure.bat
  47. emconfigure.py
  48. emdump
  49. emdump.bat
  50. emdwp
  51. emdwp.bat
  52. emmake
  53. emmake.bat
  54. emmake.py
  55. emnm
  56. emnm.bat
  57. emprofile
  58. emprofile.bat
  59. emranlib
  60. emranlib.bat
  61. emranlib.py
  62. emrun
  63. emrun.bat
  64. emrun.py
  65. emscons
  66. emscons.bat
  67. emscons.py
  68. emscripten-version.txt
  69. emscripten.py
  70. emsize
  71. emsize.bat
  72. emsize.py
  73. emstrip
  74. emstrip.bat
  75. emstrip.py
  76. emsymbolizer
  77. emsymbolizer.bat
  78. emsymbolizer.py
  79. LICENSE
  80. Makefile
  81. package-lock.json
  82. package.json
  83. README.md
  84. requirements-dev.txt
  85. SECURITY.md
README.md

emscripten logo

Main project page: https://emscripten.org

GitHub CI status: CircleCI

Chromium builder status: emscripten-releases

Overview

Emscripten compiles C and C++ to WebAssembly using LLVM and Binaryen. Emscripten output can run on the Web, in Node.js, and in wasm runtimes.

Emscripten provides Web support for popular portable APIs such as OpenGL and SDL2, allowing complex graphical native applications to be ported, such as the Unity game engine and Google Earth. It can probably port your codebase, too!

While Emscripten mostly focuses on compiling C and C++ using Clang, it can be integrated with other LLVM-using compilers (for example, Rust has Emscripten integration, with the wasm32-unknown-emscripten and asmjs-unknown-emscripten targets).

License

Emscripten is available under 2 licenses, the MIT license and the University of Illinois/NCSA Open Source License.

Both are permissive open source licenses, with little if any practical difference between them.

The reason for offering both is that (1) the MIT license is well-known and suitable for a compiler toolchain, while (2) LLVM‘s original license, the University of Illinois/NCSA Open Source License, was also offered to allow Emscripten’s code to be integrated upstream into LLVM. The second reason became less important after Emscripten switched to the LLVM wasm backend, at which point there isn't any code we expect to move back and forth between the projects; also, LLVM relicensed to Apache 2.0 + exceptions meanwhile. In practice you can just consider Emscripten as MIT licensed (which allows you to do pretty much anything you want with a compiler, including commercial and non-commercial use).

See LICENSE for the full content of the licenses.