mirror of
https://github.com/rclone/rclone.git
synced 2025-08-09 21:57:59 +02:00
lib: use atomic types
This commit is contained in:
committed by
Nick Craig-Wood
parent
01a155fb00
commit
552b6c47ff
@ -18,7 +18,7 @@ var (
|
||||
unix.FALLOC_FL_KEEP_SIZE, // Default
|
||||
unix.FALLOC_FL_KEEP_SIZE | unix.FALLOC_FL_PUNCH_HOLE, // for ZFS #3066
|
||||
}
|
||||
fallocFlagsIndex int32
|
||||
fallocFlagsIndex atomic.Int32
|
||||
preAllocateMu sync.Mutex
|
||||
)
|
||||
|
||||
@ -37,7 +37,7 @@ func PreAllocate(size int64, out *os.File) (err error) {
|
||||
|
||||
for {
|
||||
|
||||
index := atomic.LoadInt32(&fallocFlagsIndex)
|
||||
index := fallocFlagsIndex.Load()
|
||||
again:
|
||||
if index >= int32(len(fallocFlags)) {
|
||||
return nil // Fallocate is disabled
|
||||
@ -47,7 +47,7 @@ func PreAllocate(size int64, out *os.File) (err error) {
|
||||
if err == unix.ENOTSUP {
|
||||
// Try the next flags combination
|
||||
index++
|
||||
atomic.StoreInt32(&fallocFlagsIndex, index)
|
||||
fallocFlagsIndex.Store(index)
|
||||
fs.Debugf(nil, "preAllocate: got error on fallocate, trying combination %d/%d: %v", index, len(fallocFlags), err)
|
||||
goto again
|
||||
|
||||
|
Reference in New Issue
Block a user