Skip to content

Commit bd16cd0

Browse files
authored
[WASM_WORKERS] Use typedefs for async callback functions. NFC (#22870)
1 parent 01f89dc commit bd16cd0

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

system/include/emscripten/atomic.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ _EM_INLINE int64_t emscripten_atomic_notify(void *addr __attribute__((nonnull)),
229229

230230
// Represents a pending 'Atomics.waitAsync' wait operation.
231231
#define ATOMICS_WAIT_TOKEN_T int32_t
232-
232+
typedef void (*emscripten_async_wait_callback_t)(int32_t* address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void* userData);
233233
#define EMSCRIPTEN_IS_VALID_WAIT_TOKEN(token) ((token) <= 0)
234234

235235
// Issues the JavaScript 'Atomics.waitAsync' instruction:
@@ -252,9 +252,9 @@ _EM_INLINE int64_t emscripten_atomic_notify(void *addr __attribute__((nonnull)),
252252
// emscripten_atomic_cancel_wait_async() to unregister an asynchronous wait.
253253
// You can use the macro EMSCRIPTEN_IS_VALID_WAIT_TOKEN(retval) to check if
254254
// this function returned a valid wait token.
255-
ATOMICS_WAIT_TOKEN_T emscripten_atomic_wait_async(void *addr __attribute__((nonnull)),
255+
ATOMICS_WAIT_TOKEN_T emscripten_atomic_wait_async(volatile void *addr __attribute__((nonnull)),
256256
uint32_t value,
257-
void (*asyncWaitFinished)(int32_t *addr, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void *userData) __attribute__((nonnull)),
257+
emscripten_async_wait_callback_t asyncWaitFinished __attribute__((nonnull)),
258258
void *userData,
259259
double maxWaitMilliseconds);
260260

system/include/emscripten/wasm_worker.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ extern "C" {
1212
#define emscripten_wasm_worker_t int
1313
#define EMSCRIPTEN_WASM_WORKER_ID_PARENT 0
1414

15+
// Similar to emscripten_async_wait_callback_t but with a volatile first
16+
// argument.
17+
typedef void (*emscripten_async_wait_volatile_callback_t)(volatile void* address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void* userData);
18+
19+
1520
// Creates a new Worker() that is attached to executing this
1621
// WebAssembly.Instance and WebAssembly.Memory.
1722
//
@@ -184,7 +189,7 @@ void emscripten_lock_busyspin_waitinf_acquire(emscripten_lock_t *lock __attribut
184189
// use this API in Worker, you cannot utilise an infinite loop programming
185190
// model.
186191
void emscripten_lock_async_acquire(emscripten_lock_t *lock __attribute__((nonnull)),
187-
void (*asyncWaitFinished)(volatile void *address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void *userData) __attribute__((nonnull)),
192+
emscripten_async_wait_volatile_callback_t asyncWaitFinished __attribute__((nonnull)),
188193
void *userData,
189194
double maxWaitMilliseconds);
190195

@@ -218,7 +223,7 @@ int emscripten_semaphore_try_acquire(emscripten_semaphore_t *sem __attribute__((
218223
// acquired. If you use this API in Worker, you cannot run an infinite loop.
219224
void emscripten_semaphore_async_acquire(emscripten_semaphore_t *sem __attribute__((nonnull)),
220225
int num,
221-
void (*asyncWaitFinished)(volatile void *address, uint32_t idx, ATOMICS_WAIT_RESULT_T result, void *userData) __attribute__((nonnull)),
226+
emscripten_async_wait_volatile_callback_t asyncWaitFinished __attribute__((nonnull)),
222227
void *userData,
223228
double maxWaitMilliseconds);
224229

@@ -269,10 +274,10 @@ bool emscripten_condvar_wait(emscripten_condvar_t *condvar __attribute__((nonnul
269274

270275
// Asynchronously wait for the given condition variable to signal.
271276
ATOMICS_WAIT_TOKEN_T emscripten_condvar_wait_async(emscripten_condvar_t *condvar __attribute__((nonnull)),
272-
emscripten_lock_t *lock __attribute__((nonnull)),
273-
void (*asyncWaitFinished)(int32_t *address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void *userData) __attribute__((nonnull)),
274-
void *userData,
275-
double maxWaitMilliseconds);
277+
emscripten_lock_t *lock __attribute__((nonnull)),
278+
emscripten_async_wait_callback_t asyncWaitFinished __attribute__((nonnull)),
279+
void *userData,
280+
double maxWaitMilliseconds);
276281

277282
// Signals the given number of waiters on the specified condition variable.
278283
// Pass numWaitersToSignal == EMSCRIPTEN_NOTIFY_ALL_WAITERS to wake all waiters

system/lib/wasm_worker/library_wasm_worker.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ bool emscripten_condvar_wait(emscripten_condvar_t *condvar, emscripten_lock_t *l
231231
}
232232

233233
ATOMICS_WAIT_TOKEN_T emscripten_condvar_wait_async(emscripten_condvar_t *condvar,
234-
emscripten_lock_t *lock,
235-
void (*asyncWaitFinished)(int32_t *address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void *userData),
236-
void *userData,
237-
double maxWaitMilliseconds)
234+
emscripten_lock_t *lock,
235+
emscripten_async_wait_callback_t asyncWaitFinished,
236+
void *userData,
237+
double maxWaitMilliseconds)
238238
{
239239
int val = emscripten_atomic_load_u32((void*)condvar);
240240
emscripten_lock_release(lock);

0 commit comments

Comments
 (0)