sync.Mutex was replaced by sync.RWMutex for SongList.
This commit is contained in:
parent
1d50bbe790
commit
f53f30963d
@ -45,7 +45,7 @@ func (s *Song) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SongList struct {
|
type SongList struct {
|
||||||
sync.Mutex
|
sync.RWMutex
|
||||||
current Song
|
current Song
|
||||||
lastSongs []Song
|
lastSongs []Song
|
||||||
maxLen int
|
maxLen int
|
||||||
@ -76,8 +76,8 @@ func (sl *SongList) Add(newSong Song) {
|
|||||||
|
|
||||||
// Current returns a currently playing song.
|
// Current returns a currently playing song.
|
||||||
func (sl *SongList) Current() *Song {
|
func (sl *SongList) Current() *Song {
|
||||||
sl.Lock()
|
sl.RLock()
|
||||||
defer sl.Unlock()
|
defer sl.RUnlock()
|
||||||
if sl.current.StartAt.Year() == 1 {
|
if sl.current.StartAt.Year() == 1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -96,8 +96,8 @@ func (sl *SongList) UpdateCurrentMaxListeners(listeners int) {
|
|||||||
|
|
||||||
// List returns a list of lastly played songs.
|
// List returns a list of lastly played songs.
|
||||||
func (sl *SongList) List() []Song {
|
func (sl *SongList) List() []Song {
|
||||||
sl.Lock()
|
sl.RLock()
|
||||||
defer sl.Unlock()
|
defer sl.RUnlock()
|
||||||
return sl.lastSongs
|
return sl.lastSongs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user