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:
parent
9b537f24bd
commit
664a618c06
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue