Skip to content

Commit a05b7e6

Browse files
Beuckripken
authored andcommitted
emscripten_has_asyncify() (#9734)
Checks if ASYNCIFY was used in the build. This can help SDL decide how to sleep, Cf. emscripten-ports/SDL2#70
1 parent 2541e35 commit a05b7e6

File tree

7 files changed

+31
-1
lines changed

7 files changed

+31
-1
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ v1.39.1: 10/30/2019
2626
- Only MEMFS is included by default, others (NODEFS, IDBFS, WORKERFS, PROXYFS)
2727
must be linked in explicitly, using `-lnodefs.js`, `-lidbfs.js`',
2828
`-lworkerfs.js`, `-lproxyfs.js`. See #9645
29+
- New function emscripten_has_asyncify()
2930

3031
v1.39.0: 10/18/2019
3132
-------------------

site/source/docs/api_reference/emscripten.h.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,13 @@ Functions
992992
:returns: The value of the specified setting. Note that for values other than an integer, a string is returned (cast the ``int`` return value to a ``char*``).
993993
:rtype: int
994994
995+
.. c:function:: int emscripten_has_asyncify()
996+
997+
Returns whether pseudo-synchronous functions can be used.
998+
999+
:rtype: int
1000+
:returns: 1 if program was compiled with ASYNCIFY=1 or EMTERPRETER_ASYNC=1, 0 otherwise.
1001+
9951002
9961003
.. c:function:: void emscripten_debugger()
9971004

src/library.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,6 +4258,10 @@ LibraryManager.library = {
42584258
return cache[fullname] = allocate(intArrayFromString(ret + ''), 'i8', ALLOC_NORMAL);
42594259
},
42604260

4261+
emscripten_has_asyncify: function() {
4262+
return {{{ ASYNCIFY || EMTERPRETIFY_ASYNC }}};
4263+
},
4264+
42614265
emscripten_debugger: function() {
42624266
debugger;
42634267
},

system/include/emscripten/emscripten.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ int emscripten_get_worker_queue_size(worker_handle worker);
225225
// misc.
226226

227227
int emscripten_get_compiler_setting(const char *name);
228+
int emscripten_has_asyncify();
228229

229230
void emscripten_debugger(void);
230231

tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE.sent

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ _emscripten_gluOrtho2D
887887
_emscripten_gluPerspective
888888
_emscripten_gluProject
889889
_emscripten_gluUnProject
890+
_emscripten_has_asyncify
890891
_emscripten_hide_mouse
891892
_emscripten_html5_remove_all_event_listeners
892893
_emscripten_idb_async_delete

tests/test_core.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,22 @@ def test_emscripten_get_compiler_setting(self):
17581758
self.set_setting('RETAIN_COMPILER_SETTINGS', 1)
17591759
self.do_run(open(src).read(), open(output).read().replace('waka', shared.EMSCRIPTEN_VERSION))
17601760

1761+
@no_fastcomp('ASYNCIFY has been removed from fastcomp')
1762+
def test_emscripten_has_asyncify(self):
1763+
src = r'''
1764+
#include <stdio.h>
1765+
#include <emscripten.h>
1766+
1767+
int main() {
1768+
printf("%d\n", emscripten_has_asyncify());
1769+
return 0;
1770+
}
1771+
'''
1772+
self.set_setting('ASYNCIFY', 0)
1773+
self.do_run(src, '0')
1774+
self.set_setting('ASYNCIFY', 1)
1775+
self.do_run(src, '1')
1776+
17611777
# TODO: test only worked in non-fastcomp
17621778
def test_inlinejs(self):
17631779
self.skipTest('non-fastcomp is deprecated and fails in 3.5') # only supports EM_ASM

tests/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8113,7 +8113,7 @@ def test_metadce_hello(self, *args):
81138113
4, [], [], 8, 0, 0, 0), # noqa; totally empty!
81148114
# we don't metadce with linkable code! other modules may want stuff
81158115
# don't compare the # of functions in a main module, which changes a lot
8116-
'main_module_1': (['-O3', '-s', 'MAIN_MODULE=1'], 1600, [], [], 226403, None, 107, None), # noqa
8116+
'main_module_1': (['-O3', '-s', 'MAIN_MODULE=1'], 1601, [], [], 226403, None, 107, None), # noqa
81178117
'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 13, [], [], 10017, 13, 9, 20), # noqa
81188118
})
81198119
@no_wasm_backend()

0 commit comments

Comments
 (0)