adb: don't hold queue lock while performing callbacks.

Fix yet another source of deadlocks.

Bug: http://b/62020217
Test: unplugged device on darwin
Change-Id: I3fb0b3a84c56aed7d0da8ddba36e2d01fdb682ee
This commit is contained in:
Josh Gao 2017-06-05 14:54:45 -07:00
parent 9b537f24bd
commit 664a618c06
1 changed files with 9 additions and 4 deletions

View File

@ -74,13 +74,18 @@ class BlockingQueue {
template <typename Fn>
void PopAll(Fn fn) {
std::unique_lock<std::mutex> lock(mutex);
cv.wait(lock, [this]() { return !queue.empty(); });
std::vector<T> popped;
for (const T& t : queue) {
{
std::unique_lock<std::mutex> lock(mutex);
cv.wait(lock, [this]() { return !queue.empty(); });
popped = std::move(queue);
queue.clear();
}
for (const T& t : popped) {
fn(t);
}
queue.clear();
}
};