From f53f30963dbae4e7275f596ddf108d9becfb8c79 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 7 Oct 2023 05:16:16 +0400 Subject: [PATCH] sync.Mutex was replaced by sync.RWMutex for SongList. --- internal/radio/song.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/radio/song.go b/internal/radio/song.go index b2e4214..e53d7ce 100644 --- a/internal/radio/song.go +++ b/internal/radio/song.go @@ -45,7 +45,7 @@ func (s *Song) MarshalJSON() ([]byte, error) { } type SongList struct { - sync.Mutex + sync.RWMutex current Song lastSongs []Song maxLen int @@ -76,8 +76,8 @@ func (sl *SongList) Add(newSong Song) { // Current returns a currently playing song. func (sl *SongList) Current() *Song { - sl.Lock() - defer sl.Unlock() + sl.RLock() + defer sl.RUnlock() if sl.current.StartAt.Year() == 1 { return nil } @@ -96,8 +96,8 @@ func (sl *SongList) UpdateCurrentMaxListeners(listeners int) { // List returns a list of lastly played songs. func (sl *SongList) List() []Song { - sl.Lock() - defer sl.Unlock() + sl.RLock() + defer sl.RUnlock() return sl.lastSongs }