Skip to content

🎧 Your Personal Streaming Service

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

Deluan6dce4b247875
diff --git a/utils/atomic.go b/utils/atomic.go
deleted file mode 100644
index 66b69546c..000000000
--- a/utils/atomic.go
+++ /dev/null
@@ -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)
-}
diff --git a/utils/atomic_test.go b/utils/atomic_test.go
deleted file mode 100644
index ab3f0959a..000000000
--- a/utils/atomic_test.go
+++ /dev/null
@@ -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())
- })
-})
diff --git a/utils/cache/file_caches.go b/utils/cache/file_caches.go
index b2fe48328..d64187298 100644
--- a/utils/cache/file_caches.go
+++ b/utils/cache/file_caches.go
@@ -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 {