Skip to content

Commit 35c5619

Browse files
committed
Tweak.
1 parent b51234c commit 35c5619

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

vfs/os_linux.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ func osLock(file *os.File, typ int16, start, len int64, timeout time.Duration, d
5353
if errno, _ := err.(unix.Errno); errno != unix.EAGAIN {
5454
break
5555
}
56-
if timeout < time.Since(before) {
56+
if time.Since(before) > timeout {
5757
break
5858
}
59-
time.Sleep(time.Duration(rand.Int63n(int64(time.Millisecond))))
59+
const sleepIncrement = 1024*1024 - 1 // power of two, ~1ms
60+
time.Sleep(time.Duration(rand.Int63() & sleepIncrement))
6061
}
6162
}
6263
return osLockErrorCode(err, def)

vfs/os_windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ func osLock(file *os.File, flags, start, len uint32, timeout time.Duration, def
134134
if errno, _ := err.(windows.Errno); errno != windows.ERROR_LOCK_VIOLATION {
135135
break
136136
}
137-
if timeout < time.Since(before) {
137+
if time.Since(before) > timeout {
138138
break
139139
}
140-
time.Sleep(time.Duration(rand.Int63n(int64(time.Millisecond))))
140+
const sleepIncrement = 1024*1024 - 1 // power of two, ~1ms
141+
time.Sleep(time.Duration(rand.Int63() & sleepIncrement))
141142
}
142143
}
143144
return osLockErrorCode(err, def)

0 commit comments

Comments
 (0)