diff options
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go')
-rw-r--r-- | vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go b/vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go index 4cad777d3..4f6149ba3 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go @@ -28,27 +28,25 @@ func osGetReservedLock(file *os.File) _ErrorCode { return osWriteLock(file, _RESERVED_BYTE, 1, 0) } -func osGetPendingLock(file *os.File, block bool) _ErrorCode { - var timeout time.Duration - if block { - timeout = -1 - } - - // Acquire the PENDING lock. - return osWriteLock(file, _PENDING_BYTE, 1, timeout) -} - -func osGetExclusiveLock(file *os.File, block bool) _ErrorCode { - var timeout time.Duration - if block { - timeout = time.Millisecond +func osGetExclusiveLock(file *os.File, state *LockLevel) _ErrorCode { + // A PENDING lock is needed before releasing the SHARED lock. + if *state < LOCK_PENDING { + // If we were RESERVED, we can block indefinitely. + var timeout time.Duration + if *state == LOCK_RESERVED { + timeout = -1 + } + if rc := osWriteLock(file, _PENDING_BYTE, 1, timeout); rc != _OK { + return rc + } + *state = LOCK_PENDING } // Release the SHARED lock. osUnlock(file, _SHARED_FIRST, _SHARED_SIZE) // Acquire the EXCLUSIVE lock. - rc := osWriteLock(file, _SHARED_FIRST, _SHARED_SIZE, timeout) + rc := osWriteLock(file, _SHARED_FIRST, _SHARED_SIZE, time.Millisecond) if rc != _OK { // Reacquire the SHARED lock. @@ -64,9 +62,7 @@ func osDowngradeLock(file *os.File, state LockLevel) _ErrorCode { // Reacquire the SHARED lock. if rc := osReadLock(file, _SHARED_FIRST, _SHARED_SIZE, 0); rc != _OK { - // This should never happen. - // We should always be able to reacquire the read lock. - // notest + // notest // this should never happen return _IOERR_RDLOCK } } |