Skip to content

Commit 8d0342e

Browse files
committed
do not wait threads on wasi since worker may throw
1 parent 96e3572 commit 8d0342e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/emnapi/src/uv/threadpool.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include "uv-common.h"
3030
#include "common.h"
3131

32+
#if defined(__wasi__) && defined(_REENTRANT)
33+
#define __EMNAPI_WASI_THREADS__
34+
#endif
35+
3236
#define MAX_THREADPOOL_SIZE 1024
3337

3438
static uv_once_t once = UV_ONCE_INIT;
@@ -61,8 +65,9 @@ static void* worker(void* arg) {
6165
struct uv__work* w;
6266
QUEUE* q;
6367
int is_slow_work;
64-
68+
#ifndef __EMNAPI_WASI_THREADS__
6569
uv_sem_post((uv_sem_t*) arg);
70+
#endif
6671
arg = NULL;
6772

6873
uv_mutex_lock(&mutex);
@@ -199,7 +204,9 @@ static void init_threads(void) {
199204
#if !defined(EMNAPI_WORKER_POOL_SIZE) || !(EMNAPI_WORKER_POOL_SIZE > 0)
200205
const char* val;
201206
#endif
207+
#ifndef __EMNAPI_WASI_THREADS__
202208
uv_sem_t sem;
209+
#endif
203210

204211
#if defined(EMNAPI_WORKER_POOL_SIZE) && EMNAPI_WORKER_POOL_SIZE > 0
205212
nthreads = EMNAPI_WORKER_POOL_SIZE;
@@ -233,20 +240,30 @@ static void init_threads(void) {
233240
QUEUE_INIT(&slow_io_pending_wq);
234241
QUEUE_INIT(&run_slow_work_message);
235242

243+
#ifndef __EMNAPI_WASI_THREADS__
236244
if (uv_sem_init(&sem, 0))
237245
abort();
246+
#endif
238247

248+
#ifndef __EMNAPI_WASI_THREADS__
239249
for (i = 0; i < nthreads; i++)
240250
if (uv_thread_create(threads + i, (uv_thread_cb) worker, &sem))
241251
abort();
252+
#else
253+
for (i = 0; i < nthreads; i++)
254+
if (uv_thread_create(threads + i, (uv_thread_cb) worker, NULL))
255+
abort();
256+
#endif
242257

258+
#ifndef __EMNAPI_WASI_THREADS__
243259
for (i = 0; i < nthreads; i++)
244260
uv_sem_wait(&sem);
245261

246262
uv_sem_destroy(&sem);
247263

248264
for (i = 0; i < nthreads; i++)
249265
_emnapi_worker_unref(*(threads + i));
266+
#endif
250267
}
251268

252269

0 commit comments

Comments
 (0)