Skip to content
Merged
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
13 changes: 10 additions & 3 deletions test/webaudio/audioworklet_emscripten_locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an assertion? IIUC this mode should only ever be reached once?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can actually be a hit continuously until the mode changes. i.e. if the worker is is non responsive then the main thread will just repeatedly call this block forever. We could probably improve the state machine but I'm not sure I want to start messing with this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can it fail to acquire more than once? I guess maybe...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emscripten_lock_release doesn't have a return code so it can't really fail. Releasing a lock you don't have I guess is just UB

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)
Expand Down