From 35c5619880ee9ee5a3669e857882cbc6114686d4 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Wed, 4 Sep 2024 18:26:57 +0100 Subject: [PATCH] Tweak. --- vfs/os_linux.go | 5 +++-- vfs/os_windows.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/vfs/os_linux.go b/vfs/os_linux.go index 7bb78c0..e163e80 100644 --- a/vfs/os_linux.go +++ b/vfs/os_linux.go @@ -53,10 +53,11 @@ func osLock(file *os.File, typ int16, start, len int64, timeout time.Duration, d if errno, _ := err.(unix.Errno); errno != unix.EAGAIN { break } - if timeout < time.Since(before) { + if time.Since(before) > timeout { break } - time.Sleep(time.Duration(rand.Int63n(int64(time.Millisecond)))) + const sleepIncrement = 1024*1024 - 1 // power of two, ~1ms + time.Sleep(time.Duration(rand.Int63() & sleepIncrement)) } } return osLockErrorCode(err, def) diff --git a/vfs/os_windows.go b/vfs/os_windows.go index 351e819..4cad777 100644 --- a/vfs/os_windows.go +++ b/vfs/os_windows.go @@ -134,10 +134,11 @@ func osLock(file *os.File, flags, start, len uint32, timeout time.Duration, def if errno, _ := err.(windows.Errno); errno != windows.ERROR_LOCK_VIOLATION { break } - if timeout < time.Since(before) { + if time.Since(before) > timeout { break } - time.Sleep(time.Duration(rand.Int63n(int64(time.Millisecond)))) + const sleepIncrement = 1024*1024 - 1 // power of two, ~1ms + time.Sleep(time.Duration(rand.Int63() & sleepIncrement)) } } return osLockErrorCode(err, def)