Skip to content

Commit cd45112

Browse files
committed
use __WASI_ERRNO_BUSY in tsfn JS lock
1 parent 725630f commit cd45112

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

packages/emnapi/src/threadsafe-function.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,18 @@ const emnapiTSFN = {
258258
const i32a = new Int32Array(wasmMemory.buffer, index, 1)
259259
if (isBrowserMain) {
260260
while (true) {
261-
const oldValue = Atomics.compareExchange(i32a, 0, 0, 1)
261+
const oldValue = Atomics.compareExchange(i32a, 0, 0, 10)
262262
if (oldValue === 0) {
263263
return
264264
}
265265
}
266266
} else {
267267
while (true) {
268-
const oldValue = Atomics.compareExchange(i32a, 0, 0, 1)
268+
const oldValue = Atomics.compareExchange(i32a, 0, 0, 10)
269269
if (oldValue === 0) {
270270
return
271271
}
272-
Atomics.wait(i32a, 0, 1)
272+
Atomics.wait(i32a, 0, 10)
273273
}
274274
}
275275
},
@@ -278,20 +278,20 @@ const emnapiTSFN = {
278278
const again = (): void => { fn() }
279279
const fn = (): void => {
280280
const i32a = new Int32Array(wasmMemory.buffer, index, 1)
281-
const oldValue = Atomics.compareExchange(i32a, 0, 0, 1)
281+
const oldValue = Atomics.compareExchange(i32a, 0, 0, 10)
282282
if (oldValue === 0) {
283283
resolve()
284284
return
285285
}
286-
(Atomics as any).waitAsync(i32a, 0, 1).value.then(again)
286+
(Atomics as any).waitAsync(i32a, 0, 10).value.then(again)
287287
}
288288
fn()
289289
})
290290
}, */
291291
unlock () {
292292
const i32a = new Int32Array(wasmMemory.buffer, index, 1)
293-
const oldValue = Atomics.compareExchange(i32a, 0, 1, 0)
294-
if (oldValue !== 1) {
293+
const oldValue = Atomics.compareExchange(i32a, 0, 10, 0)
294+
if (oldValue !== 10) {
295295
throw new Error('Tried to unlock while not holding the mutex')
296296
}
297297
Atomics.notify(i32a, 0, 1)

packages/test/script/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const pthread = [
2121
'node-addon-api/**/*',
2222
'pool/**/*',
2323
'tsfn/**/*',
24+
'tsfn_shutdown/**/*',
2425
'async_cleanup_hook/**/*',
2526
'string/string-pthread.test.js',
2627
'uv_threadpool_size/**/*',

0 commit comments

Comments
 (0)