Remove custom atomic.Bool, we are now at Go 1.19

This commit is contained in:
Deluan 2023-02-15 21:18:24 -05:00
parent 10108c63c9
commit 6dce4b2478
3 changed files with 4 additions and 48 deletions

View File

@ -1,17 +0,0 @@
package utils
import "sync/atomic"
type AtomicBool struct{ flag uint32 }
func (b *AtomicBool) Get() bool {
return atomic.LoadUint32(&(b.flag)) != 0
}
func (b *AtomicBool) Set(value bool) {
var i uint32 = 0
if value {
i = 1
}
atomic.StoreUint32(&(b.flag), i)
}

View File

@ -1,27 +0,0 @@
package utils_test
import (
"github.com/navidrome/navidrome/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("AtomicBool", func() {
var b utils.AtomicBool
BeforeEach(func() {
b = utils.AtomicBool{}
})
It("initializes with value = false", func() {
Expect(b.Get()).To(BeFalse())
})
It("sets value", func() {
b.Set(true)
Expect(b.Get()).To(BeTrue())
b.Set(false)
Expect(b.Get()).To(BeFalse())
})
})

View File

@ -6,6 +6,7 @@ import (
"io"
"path/filepath"
"sync"
"sync/atomic"
"time"
"github.com/djherbis/fscache"
@ -14,7 +15,6 @@ import (
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/utils"
)
type Item interface {
@ -46,7 +46,7 @@ func NewFileCache(name, cacheSize, cacheFolder string, maxItems int, getReader R
fc.cache = cache
fc.disabled = cache == nil || err != nil
log.Info("Finished initializing cache", "cache", fc.name, "maxSize", fc.cacheSize, "elapsedTime", time.Since(start))
fc.ready.Set(true)
fc.ready.Store(true)
if err != nil {
log.Error(fmt.Sprintf("Cache %s will be DISABLED due to previous errors", "name"), fc.name, err)
}
@ -66,7 +66,7 @@ type fileCache struct {
cache fscache.Cache
getReader ReadFunc
disabled bool
ready utils.AtomicBool
ready atomic.Bool
mutex *sync.RWMutex
}
@ -74,7 +74,7 @@ func (fc *fileCache) Available(_ context.Context) bool {
fc.mutex.RLock()
defer fc.mutex.RUnlock()
return fc.ready.Get() && !fc.disabled
return fc.ready.Load() && !fc.disabled
}
func (fc *fileCache) invalidate(ctx context.Context, key string) error {