Commit 1c6c8e7b authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

ohplaylist::insert: use proper locking, not sequence adjustements to fix the...

ohplaylist::insert: use proper locking, not sequence adjustements to fix the cache update issue. The sequence change did not work for many changes sent to mpd 0.21
parent ed3e25ae
...@@ -567,6 +567,7 @@ bool OHPlaylist::cacheFind(const string& uri, string& meta) ...@@ -567,6 +567,7 @@ bool OHPlaylist::cacheFind(const string& uri, string& meta)
// Returns a 800 fault code if the given id is not in the playlist. // Returns a 800 fault code if the given id is not in the playlist.
int OHPlaylist::ohread(const SoapIncoming& sc, SoapOutgoing& data) int OHPlaylist::ohread(const SoapIncoming& sc, SoapOutgoing& data)
{ {
std::unique_lock<std::mutex> lock(m_statemutex);
int id; int id;
bool ok = sc.get("Id", &id); bool ok = sc.get("Id", &id);
if (!ok) { if (!ok) {
...@@ -618,6 +619,7 @@ int OHPlaylist::ohread(const SoapIncoming& sc, SoapOutgoing& data) ...@@ -618,6 +619,7 @@ int OHPlaylist::ohread(const SoapIncoming& sc, SoapOutgoing& data)
// Any ids not in the playlist are ignored. // Any ids not in the playlist are ignored.
int OHPlaylist::readList(const SoapIncoming& sc, SoapOutgoing& data) int OHPlaylist::readList(const SoapIncoming& sc, SoapOutgoing& data)
{ {
std::unique_lock<std::mutex> lock(m_statemutex);
string sids; string sids;
bool ok = sc.get("IdList", &sids); bool ok = sc.get("IdList", &sids);
LOGDEB("OHPlaylist::readList: [" << sids << "]" << endl); LOGDEB("OHPlaylist::readList: [" << sids << "]" << endl);
...@@ -710,6 +712,7 @@ bool OHPlaylist::ireadList(const vector<int>& ids, vector<UpSong>& songs) ...@@ -710,6 +712,7 @@ bool OHPlaylist::ireadList(const vector<int>& ids, vector<UpSong>& songs)
int OHPlaylist::insert(const SoapIncoming& sc, SoapOutgoing& data) int OHPlaylist::insert(const SoapIncoming& sc, SoapOutgoing& data)
{ {
LOGDEB("OHPlaylist::insert" << endl); LOGDEB("OHPlaylist::insert" << endl);
std::unique_lock<std::mutex> lock(m_statemutex);
int afterid; int afterid;
string uri, metadata; string uri, metadata;
bool ok = sc.get("AfterId", &afterid); bool ok = sc.get("AfterId", &afterid);
...@@ -768,15 +771,11 @@ bool OHPlaylist::insertUri(int afterid, const string& uri, ...@@ -768,15 +771,11 @@ bool OHPlaylist::insertUri(int afterid, const string& uri,
return false; return false;
} }
// Always update the metacache before inserting, else it may
// happen that the mpd event triggers before we can do it, and
// causes us to use MPD data to update the cache before we can do
// it.
m_metacache[uri] = metadata;
m_cachedirty = true;
m_mpdqvers = -1;
int id = m_dev->getmpdcli()->insertAfterId(uri, afterid, metaformpd); int id = m_dev->getmpdcli()->insertAfterId(uri, afterid, metaformpd);
if (id != -1) { if (id != -1) {
m_metacache[uri] = metadata;
m_cachedirty = true;
m_mpdqvers = -1;
if (newid) if (newid)
*newid = id; *newid = id;
return true; return true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment