Consistent lock timeouts.

This commit is contained in:
Nuno Cruces
2023-06-12 13:04:37 +01:00
parent 04037a75ed
commit eb8d9b95fd
3 changed files with 6 additions and 12 deletions

View File

@@ -187,17 +187,11 @@ func (m *memFile) Lock(lock vfs.LockLevel) error {
m.lockMtx.Lock()
defer m.lockMtx.Unlock()
deadline := time.Now().Add(time.Millisecond)
switch lock {
case vfs.LOCK_SHARED:
for m.pending != nil {
if time.Now().After(deadline) {
return sqlite3.BUSY
}
m.lockMtx.Unlock()
runtime.Gosched()
m.lockMtx.Lock()
if m.pending != nil {
return sqlite3.BUSY
}
m.shared++
@@ -216,8 +210,8 @@ func (m *memFile) Lock(lock vfs.LockLevel) error {
m.pending = m
}
for m.shared > 1 {
if time.Now().After(deadline) {
for start := time.Now(); m.shared > 1; {
if time.Since(start) > time.Millisecond {
return sqlite3.BUSY
}
m.lockMtx.Unlock()