mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
Locking fix.
This commit is contained in:
15
vfs_lock.go
15
vfs_lock.go
@@ -172,8 +172,21 @@ func vfsUnlock(ctx context.Context, mod api.Module, pFile uint32, eLock vfsLockS
|
||||
|
||||
func vfsCheckReservedLock(ctx context.Context, mod api.Module, pFile, pResOut uint32) uint32 {
|
||||
file := vfsFile.GetOS(ctx, mod, pFile)
|
||||
cLock := vfsFile.GetLock(ctx, mod, pFile)
|
||||
|
||||
// Connection state check.
|
||||
if cLock < _NO_LOCK || cLock > _EXCLUSIVE_LOCK {
|
||||
panic(assertErr())
|
||||
}
|
||||
|
||||
var locked bool
|
||||
var rc xErrorCode
|
||||
if cLock >= _RESERVED_LOCK {
|
||||
locked = true
|
||||
} else {
|
||||
locked, rc = vfsOS.CheckReservedLock(file)
|
||||
}
|
||||
|
||||
locked, rc := vfsOS.CheckReservedLock(file)
|
||||
var res uint32
|
||||
if locked {
|
||||
res = 1
|
||||
|
||||
@@ -51,6 +51,13 @@ func Test_vfsLock(t *testing.T) {
|
||||
if got := mem.readUint32(pOutput); got != 0 {
|
||||
t.Error("file was locked")
|
||||
}
|
||||
rc = vfsCheckReservedLock(ctx, mem.mod, pFile2, pOutput)
|
||||
if rc != _OK {
|
||||
t.Fatal("returned", rc)
|
||||
}
|
||||
if got := mem.readUint32(pOutput); got != 0 {
|
||||
t.Error("file was locked")
|
||||
}
|
||||
|
||||
rc = vfsLock(ctx, mem.mod, pFile2, _SHARED_LOCK)
|
||||
if rc != _OK {
|
||||
@@ -64,6 +71,13 @@ func Test_vfsLock(t *testing.T) {
|
||||
if got := mem.readUint32(pOutput); got != 0 {
|
||||
t.Error("file was locked")
|
||||
}
|
||||
rc = vfsCheckReservedLock(ctx, mem.mod, pFile2, pOutput)
|
||||
if rc != _OK {
|
||||
t.Fatal("returned", rc)
|
||||
}
|
||||
if got := mem.readUint32(pOutput); got != 0 {
|
||||
t.Error("file was locked")
|
||||
}
|
||||
|
||||
rc = vfsLock(ctx, mem.mod, pFile2, _RESERVED_LOCK)
|
||||
if rc != _OK {
|
||||
@@ -81,6 +95,13 @@ func Test_vfsLock(t *testing.T) {
|
||||
if got := mem.readUint32(pOutput); got == 0 {
|
||||
t.Error("file wasn't locked")
|
||||
}
|
||||
rc = vfsCheckReservedLock(ctx, mem.mod, pFile2, pOutput)
|
||||
if rc != _OK {
|
||||
t.Fatal("returned", rc)
|
||||
}
|
||||
if got := mem.readUint32(pOutput); got == 0 {
|
||||
t.Error("file wasn't locked")
|
||||
}
|
||||
|
||||
rc = vfsLock(ctx, mem.mod, pFile2, _EXCLUSIVE_LOCK)
|
||||
if rc != _OK {
|
||||
@@ -94,6 +115,13 @@ func Test_vfsLock(t *testing.T) {
|
||||
if got := mem.readUint32(pOutput); got == 0 {
|
||||
t.Error("file wasn't locked")
|
||||
}
|
||||
rc = vfsCheckReservedLock(ctx, mem.mod, pFile2, pOutput)
|
||||
if rc != _OK {
|
||||
t.Fatal("returned", rc)
|
||||
}
|
||||
if got := mem.readUint32(pOutput); got == 0 {
|
||||
t.Error("file wasn't locked")
|
||||
}
|
||||
|
||||
rc = vfsLock(ctx, mem.mod, pFile1, _SHARED_LOCK)
|
||||
if rc == _OK {
|
||||
@@ -107,6 +135,13 @@ func Test_vfsLock(t *testing.T) {
|
||||
if got := mem.readUint32(pOutput); got == 0 {
|
||||
t.Error("file wasn't locked")
|
||||
}
|
||||
rc = vfsCheckReservedLock(ctx, mem.mod, pFile2, pOutput)
|
||||
if rc != _OK {
|
||||
t.Fatal("returned", rc)
|
||||
}
|
||||
if got := mem.readUint32(pOutput); got == 0 {
|
||||
t.Error("file wasn't locked")
|
||||
}
|
||||
|
||||
rc = vfsUnlock(ctx, mem.mod, pFile2, _SHARED_LOCK)
|
||||
if rc != _OK {
|
||||
@@ -120,6 +155,13 @@ func Test_vfsLock(t *testing.T) {
|
||||
if got := mem.readUint32(pOutput); got != 0 {
|
||||
t.Error("file was locked")
|
||||
}
|
||||
rc = vfsCheckReservedLock(ctx, mem.mod, pFile2, pOutput)
|
||||
if rc != _OK {
|
||||
t.Fatal("returned", rc)
|
||||
}
|
||||
if got := mem.readUint32(pOutput); got != 0 {
|
||||
t.Error("file was locked")
|
||||
}
|
||||
|
||||
rc = vfsLock(ctx, mem.mod, pFile1, _SHARED_LOCK)
|
||||
if rc != _OK {
|
||||
|
||||
Reference in New Issue
Block a user