Add mutex initializer for wasm-c-api engine operations (#1656)

The host embedder may new/delete wasm-c-api engine simultaneously
in multiple threads, which requires lock for the operations. Since there
isn't one time called global init/destroy APIs provided by wasm-c-api,
we define a global lock and initialize it with thread mutex initializer if
the platform supports that, and use it to lock the operations of engine.

If the platform doesn't support thread mutex initializer, we require
developer to create the lock by himself to ensure the thread-safe of the
engine operations.
This commit is contained in:
Wenyong Huang
2022-10-31 11:48:07 +08:00
committed by GitHub
parent 960b613d10
commit 0f5b73ae67
12 changed files with 111 additions and 24 deletions

View File

@ -57,6 +57,8 @@ typedef pthread_cond_t korp_cond;
typedef pthread_t korp_thread;
typedef sem_t korp_sem;
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define os_thread_local_attribute __thread
#define bh_socket_t int