summaryrefslogtreecommitdiff
path: root/src/lib/encode_server_finder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-02-12 22:18:43 +0000
committerCarl Hetherington <cth@carlh.net>2019-02-12 22:18:43 +0000
commita27a2c35f0a50d5b03b3731f01f595410fe28ec7 (patch)
treea853d873d9d29a422141c547a968274e82074795 /src/lib/encode_server_finder.cc
parent94547976c896b9fb169a003e674b210d1c8583b9 (diff)
Fix a couple of deadlocks caused by emitting ServersListChanged
with a lock on _servers_mutex; handlers to that signal may call ::servers() which tries to take a lock on the same mutex.
Diffstat (limited to 'src/lib/encode_server_finder.cc')
-rw-r--r--src/lib/encode_server_finder.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/encode_server_finder.cc b/src/lib/encode_server_finder.cc
index 1837101b5..6cdd8ce3c 100644
--- a/src/lib/encode_server_finder.cc
+++ b/src/lib/encode_server_finder.cc
@@ -149,10 +149,10 @@ try
}
/* Discard servers that we haven't seen for a while */
+ bool removed = false;
{
boost::mutex::scoped_lock lm (_servers_mutex);
- bool removed = false;
list<EncodeServerDescription>::iterator i = _servers.begin();
while (i != _servers.end()) {
if (i->last_seen_seconds() > 2 * interval) {
@@ -165,10 +165,10 @@ try
++i;
}
}
+ }
- if (removed) {
- emit (boost::bind (boost::ref (ServersListChanged)));
- }
+ if (removed) {
+ emit (boost::bind (boost::ref (ServersListChanged)));
}
boost::mutex::scoped_lock lm (_search_condition_mutex);
@@ -236,8 +236,10 @@ EncodeServerFinder::handle_accept (boost::system::error_code ec, shared_ptr<Sock
(*found)->set_seen ();
} else {
EncodeServerDescription sd (ip, xml->number_child<int>("Threads"), xml->optional_number_child<int>("Version").get_value_or(0));
- boost::mutex::scoped_lock lm (_servers_mutex);
- _servers.push_back (sd);
+ {
+ boost::mutex::scoped_lock lm (_servers_mutex);
+ _servers.push_back (sd);
+ }
emit (boost::bind (boost::ref (ServersListChanged)));
}