Skip to content

Commit a47c4c9

Browse files
committed
Worker spinlocks using 'get_now()' for audio worklet compatibility
1 parent 5a0c6c8 commit a47c4c9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

system/lib/wasm_worker/library_wasm_worker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,19 @@ void emscripten_lock_waitinf_acquire(emscripten_lock_t *lock) {
105105
}
106106

107107
bool emscripten_lock_busyspin_wait_acquire(emscripten_lock_t *lock, double maxWaitMilliseconds) {
108+
// Note: using emscripten_get_now() over emscripten_performance_now() to allow
109+
// compatibility with Audio Worklets (but for workers this will defer to the
110+
// performance call with its higher granularity). We keep the non-busy locks
111+
// using the performance version since they have waits, incompatible with AWs.
108112
emscripten_lock_t val = emscripten_atomic_cas_u32((void*)lock, 0, 1);
109113
if (!val) return true;
110114

111-
double t = emscripten_performance_now();
115+
double t = emscripten_get_now();
112116
double waitEnd = t + maxWaitMilliseconds;
113117
while (t < waitEnd) {
114118
val = emscripten_atomic_cas_u32((void*)lock, 0, 1);
115119
if (!val) return true;
116-
t = emscripten_performance_now();
120+
t = emscripten_get_now();
117121
}
118122
return false;
119123
}

0 commit comments

Comments
 (0)