summaryrefslogtreecommitdiffstats
path: root/adb/adb_utils.h
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-06-05 14:54:45 -0700
committerJosh Gao <jmgao@google.com>2017-06-05 14:54:45 -0700
commit664a618c069b52d2e03d287d164dfdacd6038489 (patch)
tree5b468e88611c4488beabd22b79b503ffe0bf6cdc /adb/adb_utils.h
parent9b537f24bd375cf1954e94efbc8ee7d97b5a1e8e (diff)
downloadsystem_core-664a618c069b52d2e03d287d164dfdacd6038489.tar.gz
system_core-664a618c069b52d2e03d287d164dfdacd6038489.tar.bz2
system_core-664a618c069b52d2e03d287d164dfdacd6038489.zip
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
Diffstat (limited to 'adb/adb_utils.h')
-rw-r--r--adb/adb_utils.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/adb/adb_utils.h b/adb/adb_utils.h
index 20c63b39d..11c0ec9cc 100644
--- a/adb/adb_utils.h
+++ b/adb/adb_utils.h
@@ -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();
}
};