From 2a63ac94b24e9e4b1eb24cdfc4cf5af3544cf236 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 28 Apr 2025 13:01:19 -0700 Subject: [PATCH] Add some debugging to audioworklet_emscripten_locks.c. NFC I'm having some trouble getting this test to pass in #24190 and even having trouble getting to pass on my desktop. --- test/webaudio/audioworklet_emscripten_locks.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/webaudio/audioworklet_emscripten_locks.c b/test/webaudio/audioworklet_emscripten_locks.c index 1beff83218cb1..8191704561441 100644 --- a/test/webaudio/audioworklet_emscripten_locks.c +++ b/test/webaudio/audioworklet_emscripten_locks.c @@ -45,6 +45,7 @@ _Atomic Test whichTest = TEST_HAS_WAIT; double startTime = 0; bool ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData) { + assert(emscripten_current_thread_is_audio_worklet()); int result = 0; switch (whichTest) { case TEST_HAS_WAIT: @@ -69,7 +70,7 @@ bool ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs, whichTest = TEST_WAIT_ACQUIRE; case TEST_WAIT_ACQUIRE: // Will get unlocked in main thread, so should quickly acquire - result = emscripten_lock_busyspin_wait_acquire(&testLock, 100); + result = emscripten_lock_busyspin_wait_acquire(&testLock, 10000); emscripten_outf("TEST_WAIT_ACQUIRE: %d (expect: 1)", result); assert(result); whichTest = TEST_RELEASE; @@ -114,10 +115,16 @@ EM_JS(void, InitHtmlUi, (EMSCRIPTEN_WEBAUDIO_T audioContext), { }); bool MainLoop(double time, void* data) { + assert(!emscripten_current_thread_is_audio_worklet()); + static int didUnlock = false; switch (whichTest) { case TEST_WAIT_ACQUIRE: - // Release here to acquire in process - emscripten_lock_release(&testLock); + if (!didUnlock) { + emscripten_out("main thread releasing lock"); + // Release here to acquire in process + emscripten_lock_release(&testLock); + didUnlock = true; + } break; case TEST_WAIT_INFINTE_1: // Spin here until released in process (but don't change test until we know this case ran)