diff options
author | stephan <stephan@noemail.net> | 2022-10-04 00:54:00 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-10-04 00:54:00 +0000 |
commit | 3c272ba380084e48e583c13898aeac1aa3cc4f86 (patch) | |
tree | 2c3b43f9f9325dc1d66c3e1f2d6c601d37ca1fed /ext/wasm/sqlite3-opfs-async-proxy.js | |
parent | 88838f6b95fc468e7df46d0cb223dace60cf6f79 (diff) | |
download | sqlite-3c272ba380084e48e583c13898aeac1aa3cc4f86.tar.gz sqlite-3c272ba380084e48e583c13898aeac1aa3cc4f86.zip |
Add a test/debug mechanism to shut down the OPFS async listener so that it can be inspected (it normally can't be because its tight event-listening loop ties up the thread) and then restarted.
FossilOrigin-Name: 7d0bcff4e9b899cd25b393b9f0a02c5dcee2e229f0a0fa01719c7dcd7dcbe7c1
Diffstat (limited to 'ext/wasm/sqlite3-opfs-async-proxy.js')
-rw-r--r-- | ext/wasm/sqlite3-opfs-async-proxy.js | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/ext/wasm/sqlite3-opfs-async-proxy.js b/ext/wasm/sqlite3-opfs-async-proxy.js index 0abc3ee23..58bbf7928 100644 --- a/ext/wasm/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/sqlite3-opfs-async-proxy.js @@ -208,17 +208,28 @@ const wTimeEnd = ()=>( ); /** + Set to true by the 'opfs-async-shutdown' command to quite the wait loop. + This is only intended for debugging purposes: we cannot inspect this + file's state while the tight waitLoop() is running. +*/ +let flagAsyncShutdown = false; + +/** Asynchronous wrappers for sqlite3_vfs and sqlite3_io_methods methods. Maintenance reminder: members are in alphabetical order to simplify finding them. */ const vfsAsyncImpls = { - 'async-metrics': async ()=>{ - mTimeStart('async-metrics'); + 'opfs-async-metrics': async ()=>{ + mTimeStart('opfs-async-metrics'); metrics.dump(); - storeAndNotify('async-metrics', 0); + storeAndNotify('opfs-async-metrics', 0); mTimeEnd(); }, + 'opfs-async-shutdown': async ()=>{ + flagAsyncShutdown = true; + storeAndNotify('opfs-async-shutdown', 0); + }, mkdir: async (dirname)=>{ mTimeStart('mkdir'); let rc = 0; @@ -597,7 +608,7 @@ const waitLoop = async function f(){ const relinquishTime = 1000; let lastOpTime = performance.now(); let now; - while(true){ + while(!flagAsyncShutdown){ try { if('timed-out'===Atomics.wait( state.sabOPView, state.opIds.whichOp, 0, waitTime @@ -669,6 +680,16 @@ navigator.storage.getDirectory().then(function(d){ waitLoop(); break; } + case 'opfs-async-restart': + if(flagAsyncShutdown){ + warn("Restarting after opfs-async-shutdown. Might or might not work."); + flagAsyncShutdown = false; + waitLoop(); + } + break; + case 'opfs-async-metrics': + metrics.dump(); + break; } }; wMsg('opfs-async-loaded'); |