66#include < assert.h>
77
88// Tests that these audio worklet compatible functions work:
9+ // - emscripten_thread_supports_atomics_wait()
910// - emscripten_lock_init()
1011// - emscripten_lock_busyspin_wait_acquire()
1112// - emscripten_lock_busyspin_waitinf_acquire()
@@ -17,9 +18,16 @@ emscripten_lock_t testLock = EMSCRIPTEN_LOCK_T_STATIC_INITIALIZER;
1718int testSuccess = 0 ;
1819
1920bool ProcessAudio (int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData) {
21+ // We're in the audio worklet so no wait support
2022 int supportsAtomicWait = emscripten_thread_supports_atomics_wait ();
2123 printf (" supportsAtomicWait: %d\n " , supportsAtomicWait);
2224 assert (!supportsAtomicWait);
25+
26+ // Fail to grab the lock
27+ int tryLock = emscripten_lock_try_acquire (&testLock);
28+ printf (" emscripten_lock_try_acquire: %d\n " , tryLock);
29+ assert (!tryLock);
30+
2331 // emscripten_futex_wake(&futexLocation, 1);
2432 printf (" %f\n " , emscripten_get_now ());
2533
@@ -67,7 +75,11 @@ void WebAudioWorkletThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, bool s
6775uint8_t wasmAudioWorkletStack[4096 ];
6876
6977int main () {
78+ // Main thread init and acquire (work passes to the processor)
7079 emscripten_lock_init (&testLock);
80+ int hasLock = emscripten_lock_busyspin_wait_acquire (&testLock, 0 );
81+ assert (hasLock);
82+
7183 emscripten_set_timeout_loop (PollTestSuccess, 10 , 0 );
7284 EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context (0 );
7385 emscripten_start_wasm_audio_worklet_thread_async (context, wasmAudioWorkletStack, sizeof (wasmAudioWorkletStack), WebAudioWorkletThreadInitialized, 0 );
0 commit comments