|
| 1 | +#include <emscripten/wasm_worker.h> |
1 | 2 | #include <emscripten/webaudio.h>
|
2 |
| -#include <emscripten/threading.h> |
3 | 3 | #include <stdio.h>
|
4 | 4 | #include <stdlib.h>
|
5 | 5 | #include <assert.h>
|
6 | 6 |
|
7 |
| -// Tests that |
8 |
| -// - _emscripten_thread_supports_atomics_wait() returns true in a Wasm Audio Worklet. |
9 |
| -// - emscripten_futex_wake() does not crash in a Wasm Audio Worklet. |
10 |
| -// - emscripten_futex_wait() does not crash in a Wasm Audio Worklet. |
| 7 | +// Tests that these audio worklet compatible functions work: |
| 8 | +// - emscripten_lock_init() |
| 9 | +// - emscripten_lock_busyspin_wait_acquire() |
| 10 | +// - emscripten_lock_busyspin_waitinf_acquire() |
| 11 | +// - emscripten_lock_try_acquire() |
| 12 | +// - emscripten_lock_release() |
11 | 13 | // - emscripten_get_now() does not crash in a Wasm Audio Worklet.
|
12 | 14 |
|
13 |
| -int futexLocation = 0; |
| 15 | +// Todo: add/find a way to verify atomic wait fails? |
| 16 | + |
| 17 | +emscripten_lock_t testLock = EMSCRIPTEN_LOCK_T_STATIC_INITIALIZER; |
14 | 18 | int testSuccess = 0;
|
15 | 19 |
|
16 | 20 | bool ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData) {
|
17 |
| - int supportsAtomicWait = _emscripten_thread_supports_atomics_wait(); |
18 |
| - printf("supportsAtomicWait: %d\n", supportsAtomicWait); |
19 |
| - assert(!supportsAtomicWait); |
20 |
| - emscripten_futex_wake(&futexLocation, 1); |
| 21 | + //emscripten_futex_wake(&futexLocation, 1); |
21 | 22 | printf("%f\n", emscripten_get_now());
|
22 | 23 |
|
23 |
| - emscripten_futex_wait(&futexLocation, 1, /*maxWaitMs=*/2); |
| 24 | + //emscripten_futex_wait(&futexLocation, 1, /*maxWaitMs=*/2); |
24 | 25 | testSuccess = 1;
|
25 | 26 |
|
26 | 27 | return false;
|
@@ -64,6 +65,7 @@ void WebAudioWorkletThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, bool s
|
64 | 65 | uint8_t wasmAudioWorkletStack[4096];
|
65 | 66 |
|
66 | 67 | int main() {
|
| 68 | + emscripten_lock_init(&testLock); |
67 | 69 | emscripten_set_timeout_loop(PollTestSuccess, 10, 0);
|
68 | 70 | EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(0);
|
69 | 71 | emscripten_start_wasm_audio_worklet_thread_async(context, wasmAudioWorkletStack, sizeof(wasmAudioWorkletStack), WebAudioWorkletThreadInitialized, 0);
|
|
0 commit comments