Skip to content

Commit

Permalink
Re-enable extern-pre-js and extern-post-js under pthreads
Browse files Browse the repository at this point in the history
In emscripten-core#21701 the running of extern-pre/post-js in pthreads was disabled.
The reason was that we had a couple of tests that seemed to be assuming
this.  However, it turns out that there are important use cases that
depend on this code running in threads.

Instead, fix the two test cases by adding an extra condition.

Fixes: emscripten-core#22012
  • Loading branch information
sbc100 committed May 29, 2024
1 parent cb99414 commit e59abc0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9268,7 +9268,7 @@ def test_pthread_offset_converter_modularize(self):
self.set_setting('USE_OFFSET_CONVERTER')
self.set_setting('MODULARIZE')
self.set_setting('EXPORT_NAME', 'foo')
create_file('post.js', 'foo();')
create_file('post.js', 'if (!isPthread) foo();')
self.emcc_args += ['--extern-post-js', 'post.js']
if '-g' in self.emcc_args:
self.emcc_args += ['-DDEBUG']
Expand Down
2 changes: 1 addition & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def test_emcc_output_mjs(self, args):
})
@node_pthreads
def test_emcc_output_worker_mjs(self, args):
create_file('extern-post.js', 'await Module();')
create_file('extern-post.js', 'if (!isPthread) await Module();')
os.mkdir('subdir')
self.run_process([EMCC, '-o', 'subdir/hello_world.mjs',
'-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '-O1',
Expand Down
12 changes: 1 addition & 11 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,6 @@ def phase_linker_setup(options, state, newargs):
options.extern_pre_js = read_js_files(options.extern_pre_js)
options.extern_post_js = read_js_files(options.extern_post_js)

if settings.PTHREADS:
# Don't run extern pre/post code on pthreads.
if options.extern_pre_js:
options.extern_pre_js = 'if (!isPthread) {' + options.extern_pre_js + '}'
if options.extern_post_js:
options.extern_post_js = 'if (!isPthread) {' + options.extern_post_js + '}'

# TODO: support source maps with js_transform
if options.js_transform and settings.GENERATE_SOURCE_MAP:
logger.warning('disabling source maps because a js transform is being done')
Expand Down Expand Up @@ -2109,8 +2102,6 @@ def phase_final_emitting(options, state, target, wasm_target):
src = read_file(final_js)
final_js += '.epp.js'
with open(final_js, 'w', encoding='utf-8') as f:
if settings.PTHREADS and (options.extern_pre_js or options.extern_post_js):
f.write(make_pthread_detection())
f.write(options.extern_pre_js)
f.write(src)
f.write(options.extern_post_js)
Expand Down Expand Up @@ -2461,8 +2452,7 @@ def modularize(options):
''' % {'EXPORT_NAME': settings.EXPORT_NAME}

if settings.PTHREADS:
if not options.extern_pre_js and not options.extern_post_js:
src += make_pthread_detection()
src += make_pthread_detection()
src += '// When running as a pthread, construct a new instance on startup\n'
src += 'isPthread && %s();\n' % settings.EXPORT_NAME

Expand Down

0 comments on commit e59abc0

Please sign in to comment.