mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
Blocking locks improvements.
This commit is contained in:
@@ -171,5 +171,11 @@ type SharedMemory interface {
|
||||
shmMap(context.Context, api.Module, int32, int32, bool) (uint32, _ErrorCode)
|
||||
shmLock(int32, int32, _ShmFlag) _ErrorCode
|
||||
shmUnmap(bool)
|
||||
shmBarrier()
|
||||
io.Closer
|
||||
}
|
||||
|
||||
type blockingSharedMemory interface {
|
||||
SharedMemory
|
||||
shmEnableBlocking(block bool)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ncruces/go-sqlite3/internal/util"
|
||||
@@ -45,12 +46,15 @@ func NewSharedMemory(path string, flags OpenFlag) SharedMemory {
|
||||
}
|
||||
}
|
||||
|
||||
var _ blockingSharedMemory = &vfsShm{}
|
||||
|
||||
type vfsShm struct {
|
||||
*os.File
|
||||
path string
|
||||
regions []*util.MappedRegion
|
||||
readOnly bool
|
||||
blocking bool
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func (s *vfsShm) shmOpen() _ErrorCode {
|
||||
@@ -196,6 +200,11 @@ func (s *vfsShm) shmUnmap(delete bool) {
|
||||
s.File = nil
|
||||
}
|
||||
|
||||
func (s *vfsShm) shmBarrier() {
|
||||
s.Lock()
|
||||
s.Unlock()
|
||||
}
|
||||
|
||||
func (s *vfsShm) shmEnableBlocking(block bool) {
|
||||
s.blocking = block
|
||||
}
|
||||
|
||||
@@ -269,3 +269,8 @@ func (s *vfsShm) shmUnmap(delete bool) {
|
||||
}
|
||||
s.Close()
|
||||
}
|
||||
|
||||
func (s *vfsShm) shmBarrier() {
|
||||
s.lockMtx.Lock()
|
||||
s.lockMtx.Unlock()
|
||||
}
|
||||
|
||||
14
vfs/vfs.go
14
vfs/vfs.go
@@ -5,7 +5,6 @@ import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ncruces/go-sqlite3/internal/util"
|
||||
@@ -245,10 +244,9 @@ func vfsFileControl(ctx context.Context, mod api.Module, pFile uint32, op _Fcntl
|
||||
|
||||
case _FCNTL_LOCK_TIMEOUT:
|
||||
if file, ok := file.(FileSharedMemory); ok {
|
||||
if iface, ok := file.SharedMemory().(interface{ shmEnableBlocking(bool) }); ok {
|
||||
if i := util.ReadUint32(mod, pArg); i == 0 || i == 1 {
|
||||
iface.shmEnableBlocking(i != 0)
|
||||
}
|
||||
if shm, ok := file.SharedMemory().(blockingSharedMemory); ok {
|
||||
shm.shmEnableBlocking(util.ReadUint32(mod, pArg) != 0)
|
||||
return _OK
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,11 +383,9 @@ func vfsDeviceCharacteristics(ctx context.Context, mod api.Module, pFile uint32)
|
||||
return file.DeviceCharacteristics()
|
||||
}
|
||||
|
||||
var shmBarrier sync.Mutex
|
||||
|
||||
func vfsShmBarrier(ctx context.Context, mod api.Module, pFile uint32) {
|
||||
shmBarrier.Lock()
|
||||
defer shmBarrier.Unlock()
|
||||
shm := vfsFileGet(ctx, mod, pFile).(FileSharedMemory).SharedMemory()
|
||||
shm.shmBarrier()
|
||||
}
|
||||
|
||||
func vfsShmMap(ctx context.Context, mod api.Module, pFile uint32, iRegion, szRegion int32, bExtend, pp uint32) _ErrorCode {
|
||||
|
||||
Reference in New Issue
Block a user