From: stephan Date: Fri, 6 Mar 2026 09:06:24 +0000 (+0000) Subject: Reimplement the OPFS async proxy's wait-forever loop to be more async-friendly for... X-Git-Tag: major-release~100^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=831e2332027c0b70ba801bef4148b6b2ca79f8a1;p=thirdparty%2Fsqlite.git Reimplement the OPFS async proxy's wait-forever loop to be more async-friendly for upcoming changes. FossilOrigin-Name: fd775772fbb50b04c8c37977b90a708784eefed403e3668196c9d95559d3a5e1 --- diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.c-pp.js b/ext/wasm/api/sqlite3-opfs-async-proxy.c-pp.js index 0db9a99141..16e2d2aa1c 100644 --- a/ext/wasm/api/sqlite3-opfs-async-proxy.c-pp.js +++ b/ext/wasm/api/sqlite3-opfs-async-proxy.c-pp.js @@ -625,31 +625,21 @@ const installAsyncProxy = function(){ } } const opIds = state.opIds; + const opView = state.sabOPView; + const slotWhichOp = opIds.whichOp; + const idleWaitTime = state.asyncIdleWaitTime; while(!flagAsyncShutdown){ try { - if('not-equal'!==Atomics.wait( - state.sabOPView, opIds.whichOp, 0, state.asyncIdleWaitTime - )){ - /* Maintenance note: we compare against 'not-equal' because - - https://github.com/tomayac/sqlite-wasm/issues/12 - - is reporting that this occasionally, under high loads, - returns 'ok', which leads to the whichOp being 0 (which - isn't a valid operation ID and leads to an exception, - along with a corresponding ugly console log - message). Unfortunately, the conditions for that cannot - be reliably reproduced. The only place in our code which - writes a 0 to the state.opIds.whichOp SharedArrayBuffer - index is a few lines down from here, and that instance - is required in order for clear communication between - the sync half of this proxy and this half. - */ + const opId = Atomics.load(opView, slotWhichOp); + if( 0===opId ){ + const rv = Atomics.waitAsync(opView, slotWhichOp, 0, + idleWaitTime); + if( rv.async ) await rv.value; await releaseImplicitLocks(); continue; } - const opId = Atomics.exchange(state.sabOPView, opIds.whichOp, 0); const hnd = f.opHandlers[opId] ?? toss("No waitLoop handler for whichOp #",opId); + Atomics.store(opView, slotWhichOp, 0); const args = state.s11n.deserialize( true /* clear s11n to keep the caller from confusing this with an exception string written by the upcoming @@ -659,7 +649,7 @@ const installAsyncProxy = function(){ if(hnd.f) await hnd.f(...args); else error("Missing callback for opId",opId); }catch(e){ - error('in waitLoop():',e); + error('in waitLoop():', e); } } }; diff --git a/manifest b/manifest index c3f7604220..db41159ec8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Strip\sthe\sopfs-wl\s"back\sto\sformula",\sremoving\sthe\scurrent\sfalse\sstarts\sso\sthat\sthis\scan\sbe\stried\sagain\swithout\stripping\sover\sany\scruft.\sThe\scurrent\simpl\sis\ssubject,\swith\sno\sobvious\sway\sout\sof\sit,\sto\sstarvation\sin\sthe\sasync\sproxy. -D 2026-03-05T11:51:27.592 +C Reimplement\sthe\sOPFS\sasync\sproxy's\swait-forever\sloop\sto\sbe\smore\sasync-friendly\sfor\supcoming\schanges. +D 2026-03-06T09:06:24.644 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -594,7 +594,7 @@ F ext/wasm/api/sqlite3-api-oo1.c-pp.js 45454631265d9ce82685f1a64e1650ee19c8e121c F ext/wasm/api/sqlite3-api-prologue.js 98fedc159c9239b226d19567d7172300dee5ffce176e5fa2f62dd1f17d088385 F ext/wasm/api/sqlite3-api-worker1.c-pp.js 1041dd645e8e821c082b628cd8d9acf70c667430f9d45167569633ffc7567938 F ext/wasm/api/sqlite3-license-version-header.js 98d90255a12d02214db634e041c8e7f2f133d9361a8ebf000ba9c9af4c6761cc -F ext/wasm/api/sqlite3-opfs-async-proxy.c-pp.js 81d24de69b43d3c0940dbaa9bc82de193b720107e5a2ddfd31bc50640dd4903d +F ext/wasm/api/sqlite3-opfs-async-proxy.c-pp.js df2c3be6bcdbfab5c7426c14edf768d97de81af0c9d22282c618ab7c4bb3f48f F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js a61dd2b4d919d2d5d83c5c7e49b89ecbff2525ff81419f6a6dbaecaf3819c490 F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 1575ea6bbcf2da1e6df6892c17521a0c1c1c199a672e9090176ea0b88de48bd9 @@ -2191,8 +2191,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P 113bd910e12fea17f9f4a0a3baf706f15627c08cfa6b47a960a83eee761ef4dd -R 4ea42d5818e8a1a0aa1e2fe935a1308b +P d022f1f5e74dedae044801330eb099022498f359f408e69b3574885641b312f5 +R 29e425791ac08c7a9478759e76e59fc3 U stephan -Z 71a80b89b42b2027ae01cf15e67091dc +Z fa163f510f2e4230b70e49c7b3e367ed # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e12e126346..22849172c8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d022f1f5e74dedae044801330eb099022498f359f408e69b3574885641b312f5 +fd775772fbb50b04c8c37977b90a708784eefed403e3668196c9d95559d3a5e1