lib: use atomic types

This commit is contained in:
Roberto Ricci
2023-08-18 23:05:17 +02:00
committed by Nick Craig-Wood
parent 01a155fb00
commit 552b6c47ff
3 changed files with 13 additions and 13 deletions

View File

@ -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