Remove custom atomic.Bool, we are now at Go 1.19
This commit is contained in:
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -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())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Vendored
+4
-4
@@ -6,6 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/djherbis/fscache"
|
"github.com/djherbis/fscache"
|
||||||
@@ -14,7 +15,6 @@ import (
|
|||||||
"github.com/navidrome/navidrome/conf"
|
"github.com/navidrome/navidrome/conf"
|
||||||
"github.com/navidrome/navidrome/consts"
|
"github.com/navidrome/navidrome/consts"
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Item interface {
|
type Item interface {
|
||||||
@@ -46,7 +46,7 @@ func NewFileCache(name, cacheSize, cacheFolder string, maxItems int, getReader R
|
|||||||
fc.cache = cache
|
fc.cache = cache
|
||||||
fc.disabled = cache == nil || err != nil
|
fc.disabled = cache == nil || err != nil
|
||||||
log.Info("Finished initializing cache", "cache", fc.name, "maxSize", fc.cacheSize, "elapsedTime", time.Since(start))
|
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 {
|
if err != nil {
|
||||||
log.Error(fmt.Sprintf("Cache %s will be DISABLED due to previous errors", "name"), fc.name, err)
|
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
|
cache fscache.Cache
|
||||||
getReader ReadFunc
|
getReader ReadFunc
|
||||||
disabled bool
|
disabled bool
|
||||||
ready utils.AtomicBool
|
ready atomic.Bool
|
||||||
mutex *sync.RWMutex
|
mutex *sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ func (fc *fileCache) Available(_ context.Context) bool {
|
|||||||
fc.mutex.RLock()
|
fc.mutex.RLock()
|
||||||
defer fc.mutex.RUnlock()
|
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 {
|
func (fc *fileCache) invalidate(ctx context.Context, key string) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user