Depending on your familiarity with Go, mine maybe easier to follow, or not.
https://github.com/ncruces/go-sqlite3/blob/f1b00a9944730eaa9...
Depending on your familiarity with Go, mine maybe easier to follow, or not.
https://github.com/ncruces/go-sqlite3/blob/f1b00a9944730eaa9...
So after a few attempts, I _think_ I have something reasonable: https://github.com/michalc/sqlite-memory-vfs/blob/64a55c3491...
(I'm still a but stuck on PENDING I have to admit... not really sure how that fits in)
You take pending before exclusive (which should always be possible because you have reserved by then), and you should check pending before taking a shared lock (no need to check exclusive, because they got pending before exclusive).
Shared forces writers to wait; Reserved prevents new readers from upgrading to write; Pending prevents new readers from starting; and exclusive forces everyone else to wait.
I think different to yours in two ways:
- If doesn't go via PENDING if it doesn't need to. Not sure what's best really - but since RESERVED can already be skipped in some cases (recovering from a hot-journal) then so far happy with "skipping is a thing", and PENDING is private to the VFS anyway from what I can tell, so nothing else should care I think
- It doesn't do the blocking in the lock function, but depends on SQLite's core code doing it via the busy handler/timeout