Made Source Locked atomic.Bool
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
DataHoarder 2022-09-05 16:57:17 +02:00
parent efa01d5c31
commit 5b3948f68c
Signed by: DataHoarder
SSH key fingerprint: SHA256:EnPQOqPpbCa7nzalCEJY2sd9iPluFIBuJu2rDFalACI
3 changed files with 24 additions and 15 deletions

View file

@ -2,6 +2,7 @@ package audio
import (
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
"sync/atomic"
)
type float32Source struct {
@ -9,7 +10,7 @@ type float32Source struct {
SampleRate int
Channels int
Blocks chan []float32
locked bool
locked atomic.Bool
}
func newFloat32Source(bitDepth, sampleRate, channels int) TypedSource[float32] {
@ -33,8 +34,10 @@ func (s *float32Source) GetBlocks() chan []float32 {
if s.Locked() {
return nil
}
s.locked = true
return s.Blocks
if !s.locked.Swap(true) {
return s.Blocks
}
return nil
}
func (s *float32Source) Close() {
@ -54,11 +57,11 @@ func (s *float32Source) GetBitDepth() int {
}
func (s *float32Source) Locked() bool {
return s.locked
return s.locked.Load()
}
func (s *float32Source) Unlock() {
s.locked = false
s.locked.Store(false)
}
func (s *float32Source) SwapBlocks(blocks chan []float32) chan []float32 {

View file

@ -2,6 +2,7 @@ package audio
import (
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
"sync/atomic"
)
type int16Source struct {
@ -9,7 +10,7 @@ type int16Source struct {
SampleRate int
Channels int
Blocks chan []int16
locked bool
locked atomic.Bool
}
func newInt16Source(bitDepth, sampleRate, channels int) TypedSource[int16] {
@ -36,8 +37,10 @@ func (s *int16Source) GetBlocks() chan []int16 {
if s.Locked() {
return nil
}
s.locked = true
return s.Blocks
if !s.locked.Swap(true) {
return s.Blocks
}
return nil
}
func (s *int16Source) Close() {
@ -57,11 +60,11 @@ func (s *int16Source) GetBitDepth() int {
}
func (s *int16Source) Locked() bool {
return s.locked
return s.locked.Load()
}
func (s *int16Source) Unlock() {
s.locked = false
s.locked.Store(false)
}
func (s *int16Source) SwapBlocks(blocks chan []int16) chan []int16 {

View file

@ -2,6 +2,7 @@ package audio
import (
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
"sync/atomic"
)
type int32Source struct {
@ -9,7 +10,7 @@ type int32Source struct {
SampleRate int
Channels int
Blocks chan []int32
locked bool
locked atomic.Bool
}
func newInt32Source(bitDepth, sampleRate, channels int) TypedSource[int32] {
@ -36,8 +37,10 @@ func (s *int32Source) GetBlocks() chan []int32 {
if s.Locked() {
return nil
}
s.locked = true
return s.Blocks
if !s.locked.Swap(true) {
return s.Blocks
}
return nil
}
func (s *int32Source) Close() {
@ -57,11 +60,11 @@ func (s *int32Source) GetBitDepth() int {
}
func (s *int32Source) Locked() bool {
return s.locked
return s.locked.Load()
}
func (s *int32Source) Unlock() {
s.locked = false
s.locked.Store(false)
}
func (s *int32Source) SwapBlocks(blocks chan []int32) chan []int32 {