aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-17 00:17:20 +0100
committerMax Kellermann <max@duempel.org>2014-01-17 00:17:20 +0100
commit59510f509a2332b20b998eb766967241d260704a (patch)
tree5eab7100c77d6049e7f5a56433bcbc9b6b5c0a7d /src
parenta35c7bc81aec11e9720462d8258a0d3c41e2fac7 (diff)
downloadmpd-59510f509a2332b20b998eb766967241d260704a.tar.gz
mpd-59510f509a2332b20b998eb766967241d260704a.tar.xz
mpd-59510f509a2332b20b998eb766967241d260704a.zip
db/upnp: add local reference variables
Prepare to refactor some code.
Diffstat (limited to '')
-rw-r--r--src/db/upnp/Discovery.cxx27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/db/upnp/Discovery.cxx b/src/db/upnp/Discovery.cxx
index a51b57a48..8b88a0251 100644
--- a/src/db/upnp/Discovery.cxx
+++ b/src/db/upnp/Discovery.cxx
@@ -107,6 +107,9 @@ static ContentDirectoryPool contentDirectories;
static void *
discoExplorer(void *)
{
+ auto &mutex = contentDirectories.m_mutex;
+ auto &directories = contentDirectories.m_directories;
+
for (;;) {
DiscoveredTask *tsk = 0;
if (!discoveredQueue.take(tsk)) {
@@ -114,12 +117,12 @@ discoExplorer(void *)
return (void*)1;
}
- const ScopeLock protect(contentDirectories.m_mutex);
+ const ScopeLock protect(mutex);
if (!tsk->alive) {
// Device signals it is going off.
- auto it = contentDirectories.m_directories.find(tsk->deviceId);
- if (it != contentDirectories.m_directories.end()) {
- contentDirectories.m_directories.erase(it);
+ auto it = directories.find(tsk->deviceId);
+ if (it != directories.end()) {
+ directories.erase(it);
}
} else {
// Device signals its existence and well-being. Perform the
@@ -142,9 +145,9 @@ discoExplorer(void *)
}
#if defined(__clang__) || GCC_CHECK_VERSION(4,8)
- auto e = contentDirectories.m_directories.emplace(tsk->deviceId, d);
+ auto e = directories.emplace(tsk->deviceId, d);
#else
- auto e = contentDirectories.m_directories.insert(std::make_pair(tsk->deviceId, d));
+ auto e = directories.insert(std::make_pair(tsk->deviceId, d));
#endif
if (!e.second)
e.first->second = d;
@@ -199,13 +202,14 @@ void
UPnPDeviceDirectory::expireDevices()
{
const ScopeLock protect(contentDirectories.m_mutex);
+ auto &directories = contentDirectories.m_directories;
time_t now = time(0);
bool didsomething = false;
- for (auto it = contentDirectories.m_directories.begin();
- it != contentDirectories.m_directories.end();) {
+ for (auto it = directories.begin();
+ it != directories.end();) {
if (now - it->second.last_seen > it->second.expires) {
- it = contentDirectories.m_directories.erase(it);
+ it = directories.erase(it);
didsomething = true;
} else {
it++;
@@ -271,9 +275,10 @@ UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out)
expireDevices();
const ScopeLock protect(contentDirectories.m_mutex);
+ auto &directories = contentDirectories.m_directories;
- for (auto dit = contentDirectories.m_directories.begin();
- dit != contentDirectories.m_directories.end(); dit++) {
+ for (auto dit = directories.begin();
+ dit != directories.end(); dit++) {
for (const auto &service : dit->second.device.services) {
if (isCDService(service.serviceType.c_str())) {
out.emplace_back(dit->second.device, service);