Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/libsigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ sigs = {
_embind_register_value_object__sig: 'vpppppp',
_embind_register_value_object_field__sig: 'vpppppppppp',
_embind_register_void__sig: 'vpp',
_emscripten_create_audio_worklet__sig: 'viipipp',
_emscripten_create_audio_worklet__sig: 'viipippp',
_emscripten_create_wasm_worker__sig: 'iipip',
_emscripten_dlopen_js__sig: 'vpppp',
_emscripten_dlsync_threads__sig: 'v',
Expand Down
5 changes: 4 additions & 1 deletion src/lib/libwebaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ var LibraryWebAudio = {
_emscripten_create_audio_worklet__deps: [
'$_emAudioDispatchProcessorCallback',
'$stackAlloc', '$stackRestore', '$stackSave'],
_emscripten_create_audio_worklet: (wwID, contextHandle, stackLowestAddress, stackSize, callback, userData) => {
_emscripten_create_audio_worklet: (wwID, contextHandle, stackLowestAddress, stackSize, pthreadPtr, callback, userData) => {
Comment thread
sbc100 marked this conversation as resolved.

#if ASSERTIONS || WEBAUDIO_DEBUG
emAudioExpectContext(contextHandle, '_emscripten_create_audio_worklet');
Expand Down Expand Up @@ -256,6 +256,9 @@ var LibraryWebAudio = {
wasmMemory,
stackLowestAddress, // sb = stack base
stackSize, // sz = stack size
#if PTHREADS
pthreadPtr,
#endif
});
audioWorklet.port.onmessage = _emAudioDispatchProcessorCallback;
{{{ makeDynCall('viip', 'callback') }}}(contextHandle, 1/*EM_TRUE*/, userData);
Expand Down
2 changes: 1 addition & 1 deletion system/lib/libc/emscripten_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void emscripten_fetch_free(unsigned int);
// to perform the wasm worker creation.
bool _emscripten_create_wasm_worker(emscripten_wasm_worker_t wwID, void *stackLowestAddress, uint32_t stackSize, void* pthreadPtr);

void _emscripten_create_audio_worklet(emscripten_wasm_worker_t wwID, EMSCRIPTEN_WEBAUDIO_T audioContext, void *stackLowestAddress, uint32_t stackSize, EmscriptenStartWebAudioWorkletCallback callback, void *userData2);
void _emscripten_create_audio_worklet(emscripten_wasm_worker_t wwID, EMSCRIPTEN_WEBAUDIO_T audioContext, void *stackLowestAddress, uint32_t stackSize, void* pthreadPtr, EmscriptenStartWebAudioWorkletCallback callback, void *userData2);

void __resumeException(void* exn);
void __cxa_call_unexpected(void* exn);
Expand Down
6 changes: 6 additions & 0 deletions system/lib/pthread/threading_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ int _emscripten_thread_supports_atomics_wait(void);

pid_t _emscripten_get_next_tid();

// Initialize pthread data, at start of memory region pointed to `base`.
// `size` is an in/out parameter representing the size of the `base` region
// on input, and the size of new/adjusted region on output.
// Return a new/adjusted memory base to be used to stack/tls data.
void* _emscripten_init_pthread(void *base, size_t* size, pid_t tid);

// Wake the target thread in case it is blocked in emscripten_futex_wait.
// Note: If threads directly use lower level APIs such
// __builtin_wasm_memory_atomic_waitXX then they will not be woken by
Expand Down
9 changes: 8 additions & 1 deletion system/lib/wasm_worker/audio_worklet.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
// Simple wrapper function around the JS _emscripten_create_audio_worklet
// function that adds the _emscripten_get_next_tid() as arg0
void emscripten_start_wasm_audio_worklet_thread_async(EMSCRIPTEN_WEBAUDIO_T audioContext, void *stackLowestAddress, uint32_t stackSize, EmscriptenStartWebAudioWorkletCallback callback, void *userData2) {
_emscripten_create_audio_worklet(_emscripten_get_next_tid(), audioContext, stackLowestAddress, stackSize, callback, userData2);
emscripten_wasm_worker_t wwID = _emscripten_get_next_tid();
void* pthreadPtr = stackLowestAddress;
#ifdef __EMSCRIPTEN_PTHREADS__
size_t stackSize_ = stackSize;
stackLowestAddress = _emscripten_init_pthread(stackLowestAddress, &stackSize_, wwID);
stackSize = stackSize_;
#endif
_emscripten_create_audio_worklet(wwID, audioContext, stackLowestAddress, stackSize, pthreadPtr, callback, userData2);
}
6 changes: 3 additions & 3 deletions system/lib/wasm_worker/library_wasm_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ weak_alias(dummy, __pthread_tsd_size);
* In either case these sections are all aligned to `max_alignment()`
* which is the max alignment of any of the given chunks.
*/
static void* init_pthread_struct(void *stackPlusTLSAddress, pid_t tid, size_t* stackPlusTLSSize) {
void* _emscripten_init_pthread(void *stackPlusTLSAddress, size_t* stackPlusTLSSize, pid_t tid) {
// TODO: Remove duplication with pthread_create
pthread_t self = pthread_self();

Expand Down Expand Up @@ -143,7 +143,7 @@ static void* init_pthread_struct(void *stackPlusTLSAddress, pid_t tid, size_t* s

__tl_unlock();

dbg("init_pthread_struct: base=%#lx, end=%#lx, used=%zu "
dbg("_emscripten_init_pthread: base=%#lx, end=%#lx, used=%zu "
"stackold=%zu stacknew=%zu",
base,
base + *stackPlusTLSSize,
Expand Down Expand Up @@ -202,7 +202,7 @@ emscripten_wasm_worker_t emscripten_create_wasm_worker(void *stackPlusTLSAddress
emscripten_wasm_worker_t wwID = _emscripten_get_next_tid();
void* pthreadPtr = stackPlusTLSAddress;
#ifdef __EMSCRIPTEN_PTHREADS__
stackPlusTLSAddress = init_pthread_struct(stackPlusTLSAddress, wwID, &stackPlusTLSSize);
stackPlusTLSAddress = _emscripten_init_pthread(stackPlusTLSAddress, &stackPlusTLSSize, wwID);
#endif
if (!_emscripten_create_wasm_worker(wwID, stackPlusTLSAddress, stackPlusTLSSize, pthreadPtr))
return 0;
Expand Down
Loading
Loading