diff options
| author | 2025-07-18 11:56:40 +0200 | |
|---|---|---|
| committer | 2025-07-18 11:56:40 +0200 | |
| commit | eb600819854039c8d89fb1d7000f301ad3c7d542 (patch) | |
| tree | 267138dcdf3280e32ef4dde7b5a3355212bd0474 /vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go | |
| parent | [feature] Add `avif` file support (#4331) (diff) | |
| download | gotosocial-eb600819854039c8d89fb1d7000f301ad3c7d542.tar.xz | |
[chore/deps] Upgrade to go-sqlite 0.27.1 (#4334)
# Description
This brings some performance improvements and SQLite 3.50.3.
## Checklist
Please put an x inside each checkbox to indicate that you've read and followed it: `[ ]` -> `[x]`
If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).
- [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md).
- [ ] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have not leveraged AI to create the proposed changes.
- [ ] I/we have performed a self-review of added code.
- [ ] I/we have written code that is legible and maintainable by others.
- [ ] I/we have commented the added code, particularly in hard-to-understand areas.
- [ ] I/we have made any necessary changes to documentation.
- [ ] I/we have added tests that cover new code.
- [x] I/we have run tests and they pass locally with the changes.
- [ ] I/we have run `go fmt ./...` and `golangci-lint run`.
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4334
Co-authored-by: Daenney <git@noreply.sourcery.dny.nu>
Co-committed-by: Daenney <git@noreply.sourcery.dny.nu>
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go')
| -rw-r--r-- | vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go b/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go index 94347f1cc..b99070496 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go @@ -2,7 +2,6 @@ package memdb import ( "io" - "runtime" "sync" "time" @@ -85,9 +84,10 @@ type memDB struct { // +checklocks:memoryMtx refs int32 - shared int32 // +checklocks:lockMtx - pending bool // +checklocks:lockMtx - reserved bool // +checklocks:lockMtx + shared int32 // +checklocks:lockMtx + pending bool // +checklocks:lockMtx + reserved bool // +checklocks:lockMtx + waiter *sync.Cond // +checklocks:lockMtx lockMtx sync.Mutex dataMtx sync.RWMutex @@ -195,8 +195,6 @@ func (m *memFile) Size() (int64, error) { return m.size, nil } -const spinWait = 25 * time.Microsecond - func (m *memFile) Lock(lock vfs.LockLevel) error { if m.lock >= lock { return nil @@ -228,13 +226,18 @@ func (m *memFile) Lock(lock vfs.LockLevel) error { m.pending = true } - for before := time.Now(); m.shared > 1; { - if time.Since(before) > spinWait { - return sqlite3.BUSY + if m.shared > 1 { + before := time.Now() + if m.waiter == nil { + m.waiter = sync.NewCond(&m.lockMtx) + } + defer time.AfterFunc(time.Millisecond, m.waiter.Broadcast).Stop() + for m.shared > 1 { + if time.Since(before) > time.Millisecond { + return sqlite3.BUSY + } + m.waiter.Wait() } - m.lockMtx.Unlock() - runtime.Gosched() - m.lockMtx.Lock() } } @@ -257,7 +260,9 @@ func (m *memFile) Unlock(lock vfs.LockLevel) error { m.pending = false } if lock < vfs.LOCK_SHARED { - m.shared-- + if m.shared--; m.pending && m.shared <= 1 && m.waiter != nil { + m.waiter.Broadcast() + } } m.lock = lock return nil |
