Skip to content

Commit f3a4013

Browse files
committed
Refactor __wasi_fd_sync implementation
- Always call stream.stream_ops.fsync when its available. - Only use `Asyncify.handleSleep` when needed.
1 parent b624060 commit f3a4013

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/lib/libwasi.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -540,34 +540,27 @@ var WasiLibrary = {
540540
return 0;
541541
},
542542

543+
fd_sync__async: true,
543544
fd_sync: (fd) => {
544545
#if SYSCALLS_REQUIRE_FILESYSTEM
545546
var stream = SYSCALLS.getStreamFromFD(fd);
547+
var rtn = stream.stream_ops.fsync?.(stream);
546548
#if ASYNCIFY
547-
return Asyncify.handleSleep((wakeUp) => {
548-
var mount = stream.node.mount;
549-
if (!mount.type.syncfs) {
550-
// We write directly to the file system, so there's nothing to do here.
551-
wakeUp(0);
552-
return;
549+
var mount = stream.node.mount;
550+
if (mount.type.syncfs) {
551+
return Asyncify.handleSleep((wakeUp) => {
552+
mount.type.syncfs(mount, false, (err) => wakeUp(err ? {{{ cDefs.EIO }}} : 0));
553553
}
554-
mount.type.syncfs(mount, false, (err) => {
555-
wakeUp(err ? {{{ cDefs.EIO }}} : 0);
556-
});
557-
});
558-
#else
559-
if (stream.stream_ops?.fsync) {
560-
return stream.stream_ops.fsync(stream);
561554
}
562-
return 0; // we can't do anything synchronously; the in-memory FS is already synced to
555+
#endif
556+
return rtn;
563557
#endif // ASYNCIFY
564558
#elif ASSERTIONS
565559
abort('fd_sync called without SYSCALLS_REQUIRE_FILESYSTEM');
566560
#else
567561
return {{{ cDefs.ENOSYS }}};
568562
#endif // SYSCALLS_REQUIRE_FILESYSTEM
569563
},
570-
fd_sync__async: true,
571564

572565
// random.h
573566

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 245482,
2+
"a.out.js": 245471,
33
"a.out.nodebug.wasm": 573657,
4-
"total": 819139,
4+
"total": 819128,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

0 commit comments

Comments
 (0)