aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-23 22:21:45 +0100
committerMax Kellermann <max@duempel.org>2014-01-23 22:35:22 +0100
commitc9af358e4bbc39da7dfe3ce650008c12ac3f8335 (patch)
treee3b4864f5578687f005930380920a45905e1db76
parent3afcfe3330a447915d5c7806ce397cee418e51d0 (diff)
downloadmpd-c9af358e4bbc39da7dfe3ce650008c12ac3f8335.tar.gz
mpd-c9af358e4bbc39da7dfe3ce650008c12ac3f8335.tar.xz
mpd-c9af358e4bbc39da7dfe3ce650008c12ac3f8335.zip
db/upnp/Discovery: move code to LockAdd(), LockRemove()
-rw-r--r--src/db/upnp/Discovery.cxx27
-rw-r--r--src/db/upnp/Discovery.hxx3
2 files changed, 21 insertions, 9 deletions
diff --git a/src/db/upnp/Discovery.cxx b/src/db/upnp/Discovery.cxx
index 5eaf054f5..4aeb381fd 100644
--- a/src/db/upnp/Discovery.cxx
+++ b/src/db/upnp/Discovery.cxx
@@ -54,6 +54,22 @@ isMSDevice(const char *st)
}
inline void
+UPnPDeviceDirectory::LockAdd(std::string &&id, ContentDirectoryDescriptor &&d)
+{
+ const ScopeLock protect(mutex);
+ directories[std::move(id)] = std::move(d);
+}
+
+inline void
+UPnPDeviceDirectory::LockRemove(const std::string &id)
+{
+ const ScopeLock protect(mutex);
+ auto i = directories.find(id);
+ if (i != directories.end())
+ directories.erase(i);
+}
+
+inline void
UPnPDeviceDirectory::discoExplorer()
{
for (;;) {
@@ -88,10 +104,7 @@ UPnPDeviceDirectory::discoExplorer()
}
}
- mutex.lock();
- directories[std::move(tsk->deviceId)] = std::move(d);
- mutex.unlock();
-
+ LockAdd(std::move(tsk->deviceId), std::move(d));
delete tsk;
}
}
@@ -120,14 +133,10 @@ UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco)
inline int
UPnPDeviceDirectory::OnByeBye(Upnp_Discovery *disco)
{
-
if (isMSDevice(disco->DeviceType) ||
isCDService(disco->ServiceType)) {
// Device signals it is going off.
- const ScopeLock protect(mutex);
- auto it = directories.find(disco->DeviceId);
- if (it != directories.end())
- directories.erase(it);
+ LockRemove(disco->DeviceId);
}
return UPNP_E_SUCCESS;
diff --git a/src/db/upnp/Discovery.hxx b/src/db/upnp/Discovery.hxx
index 78d905369..fec9fe1fb 100644
--- a/src/db/upnp/Discovery.hxx
+++ b/src/db/upnp/Discovery.hxx
@@ -129,6 +129,9 @@ private:
*/
bool expireDevices(Error &error);
+ void LockAdd(std::string &&id, ContentDirectoryDescriptor &&d);
+ void LockRemove(const std::string &id);
+
/**
* Worker routine for the discovery queue. Get messages about
* devices appearing and disappearing, and update the