Skip to content

add opfs_close #24649

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/lib/libsigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ sigs = {
_wasmfs_opfs_set_size_access__sig: 'vpijp',
_wasmfs_opfs_set_size_file__sig: 'vpijp',
_wasmfs_opfs_write_access__sig: 'iipij',
_wasmfs_opfs_close_all__sig: 'vp',
_wasmfs_stdin_get_char__sig: 'i',
_wasmfs_thread_utils_heartbeat__sig: 'vp',
alBuffer3f__sig: 'viifff',
Expand Down
23 changes: 22 additions & 1 deletion src/lib/libwasmfs_opfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,26 @@ addToLibrary({
{{{ makeSetValue('errPtr', 0, 'err', 'i32') }}};
}
wasmfsOPFSProxyFinish(ctx);
}
},

_wasmfs_opfs_close_all__deps: ['$wasmfsOPFSAccessHandles', '$wasmfsOPFSProxyFinish'],
_wasmfs_opfs_close_all__async: {{{ !PTHREADS }}},
_wasmfs_opfs_close_all: async function(ctx) {
for (let i = 0; i < wasmfsOPFSAccessHandles.allocated.length; i++)
{
const handle = wasmfsOPFSAccessHandles.allocated[i];
if (handle && handle.close)
{
try {
await handle.close();
} catch (e) {
#if ASSERTIONS
err('unexpected error:', e, e.stack);
#endif
}
wasmfsOPFSAccessHandles.free(i);
}
}
wasmfsOPFSProxyFinish(ctx);
}
});
2 changes: 2 additions & 0 deletions system/include/emscripten/wasmfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ backend_t wasmfs_create_node_backend(const char* root __attribute__((nonnull)));
// thread.
backend_t wasmfs_create_opfs_backend(void);

void wasmfs_close_opfs_backend(backend_t backend);

// Creates a generic JSIMPL backend
backend_t wasmfs_create_jsimpl_backend(void);

Expand Down
10 changes: 10 additions & 0 deletions system/lib/wasmfs/backends/opfs_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ class OPFSBackend : public Backend {
// Symlinks not supported.
return nullptr;
}

void closeAll() {
proxy([](auto ctx) { _wasmfs_opfs_close_all(ctx.ctx); });
}
};

} // anonymous namespace
Expand All @@ -415,4 +419,10 @@ void EMSCRIPTEN_KEEPALIVE _wasmfs_opfs_record_entry(
entries->push_back({name, File::FileKind(type), 0});
}

void wasmfs_close_opfs_backend(backend_t backend) {
auto opfsBackend = static_cast<OPFSBackend*>(backend);
assert(opfsBackend && "Invalid OPFS backend");
opfsBackend->closeAll();
}

} // extern "C"
2 changes: 2 additions & 0 deletions system/lib/wasmfs/backends/opfs_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ void _wasmfs_opfs_set_size_file(em_proxying_ctx* ctx,

void _wasmfs_opfs_flush_access(em_proxying_ctx* ctx, int access_id, int* err);

void _wasmfs_opfs_close_all(em_proxying_ctx* ctx);

} // extern "C"
6 changes: 3 additions & 3 deletions test/code_size/audio_worklet_wasm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 364,
"a.js": 3853,
"a.js.gz": 2050,
"a.wasm": 1294,
"a.wasm.gz": 864,
"total": 5666,
"a.wasm": 1288,
"a.wasm.gz": 867,
"total": 5660,
"total_gz": 3278
}
8 changes: 4 additions & 4 deletions test/code_size/embind_hello_wasm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 380,
"a.js": 7266,
"a.js.gz": 3321,
"a.wasm": 7300,
"a.wasm.gz": 3348,
"total": 15118,
"total_gz": 7049
"a.wasm": 7294,
"a.wasm.gz": 3346,
"total": 15112,
"total_gz": 7047
}
8 changes: 4 additions & 4 deletions test/code_size/hello_wasm_worker_wasm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 364,
"a.js": 830,
"a.js.gz": 530,
"a.wasm": 1891,
"a.wasm.gz": 1082,
"total": 3240,
"total_gz": 1976
"a.wasm": 1885,
"a.wasm.gz": 1079,
"total": 3234,
"total_gz": 1973
}
4 changes: 2 additions & 2 deletions test/code_size/hello_webgl2_wasm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 328,
"a.js": 4386,
"a.js.gz": 2252,
"a.wasm": 8286,
"a.wasm.gz": 5617,
"a.wasm": 8278,
"a.wasm.gz": 5627,
"total": 13126,
"total_gz": 8197
}
8 changes: 4 additions & 4 deletions test/code_size/hello_webgl_wasm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 328,
"a.js": 3924,
"a.js.gz": 2092,
"a.wasm": 8286,
"a.wasm.gz": 5617,
"total": 12664,
"total_gz": 8037
"a.wasm": 8278,
"a.wasm.gz": 5627,
"total": 12656,
"total_gz": 8047
}
8 changes: 4 additions & 4 deletions test/code_size/hello_webgl_wasm2js.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"a.html": 346,
"a.html.gz": 262,
"a.js": 17605,
"a.js.gz": 9614,
"total": 17951,
"total_gz": 9876
"a.js": 17630,
"a.js.gz": 9603,
"total": 17976,
"total_gz": 9865
}
8 changes: 4 additions & 4 deletions test/code_size/math_wasm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 380,
"a.js": 110,
"a.js.gz": 125,
"a.wasm": 2687,
"a.wasm.gz": 1658,
"total": 3349,
"total_gz": 2163
"a.wasm": 2678,
"a.wasm.gz": 1655,
"total": 3340,
"total_gz": 2160
}
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O0.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15133
15135
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O1.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2673
2675
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O2.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1977
1979
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O3.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1733
1735
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_Os.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1724
1725
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_dylink.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18547
18549
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_single_file.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6611
6615
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_wasmfs.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1733
1735
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15133
15135
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15133
15135