Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WASM_WORKERS] Use typedefs for async callback functions. NFC #22870

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions system/include/emscripten/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ _EM_INLINE int64_t emscripten_atomic_notify(void *addr __attribute__((nonnull)),

// Represents a pending 'Atomics.waitAsync' wait operation.
#define ATOMICS_WAIT_TOKEN_T int32_t

typedef void (*emscripten_async_wait_callback_t)(int32_t* address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void* userData);
#define EMSCRIPTEN_IS_VALID_WAIT_TOKEN(token) ((token) <= 0)

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

Expand Down
17 changes: 11 additions & 6 deletions system/include/emscripten/wasm_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ extern "C" {
#define emscripten_wasm_worker_t int
#define EMSCRIPTEN_WASM_WORKER_ID_PARENT 0

// Similar to emscripten_async_wait_callback_t but with a volatile first
// argument.
typedef void (*emscripten_async_wait_volatile_callback_t)(volatile void* address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void* userData);


// Creates a new Worker() that is attached to executing this
// WebAssembly.Instance and WebAssembly.Memory.
//
Expand Down Expand Up @@ -184,7 +189,7 @@ void emscripten_lock_busyspin_waitinf_acquire(emscripten_lock_t *lock __attribut
// use this API in Worker, you cannot utilise an infinite loop programming
// model.
void emscripten_lock_async_acquire(emscripten_lock_t *lock __attribute__((nonnull)),
void (*asyncWaitFinished)(volatile void *address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void *userData) __attribute__((nonnull)),
emscripten_async_wait_volatile_callback_t asyncWaitFinished __attribute__((nonnull)),
void *userData,
double maxWaitMilliseconds);

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

Expand Down Expand Up @@ -269,10 +274,10 @@ bool emscripten_condvar_wait(emscripten_condvar_t *condvar __attribute__((nonnul

// Asynchronously wait for the given condition variable to signal.
ATOMICS_WAIT_TOKEN_T emscripten_condvar_wait_async(emscripten_condvar_t *condvar __attribute__((nonnull)),
emscripten_lock_t *lock __attribute__((nonnull)),
void (*asyncWaitFinished)(int32_t *address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void *userData) __attribute__((nonnull)),
void *userData,
double maxWaitMilliseconds);
emscripten_lock_t *lock __attribute__((nonnull)),
emscripten_async_wait_callback_t asyncWaitFinished __attribute__((nonnull)),
void *userData,
double maxWaitMilliseconds);

// Signals the given number of waiters on the specified condition variable.
// Pass numWaitersToSignal == EMSCRIPTEN_NOTIFY_ALL_WAITERS to wake all waiters
Expand Down
8 changes: 4 additions & 4 deletions system/lib/wasm_worker/library_wasm_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ bool emscripten_condvar_wait(emscripten_condvar_t *condvar, emscripten_lock_t *l
}

ATOMICS_WAIT_TOKEN_T emscripten_condvar_wait_async(emscripten_condvar_t *condvar,
emscripten_lock_t *lock,
void (*asyncWaitFinished)(int32_t *address, uint32_t value, ATOMICS_WAIT_RESULT_T waitResult, void *userData),
void *userData,
double maxWaitMilliseconds)
emscripten_lock_t *lock,
emscripten_async_wait_callback_t asyncWaitFinished,
void *userData,
double maxWaitMilliseconds)
{
int val = emscripten_atomic_load_u32((void*)condvar);
emscripten_lock_release(lock);
Expand Down
Loading