Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 664a618c authored by Josh Gao's avatar Josh Gao
Browse files

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
parent 9b537f24
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -74,13 +74,18 @@ class BlockingQueue {

    template <typename Fn>
    void PopAll(Fn fn) {
        std::vector<T> popped;

        {
            std::unique_lock<std::mutex> lock(mutex);
            cv.wait(lock, [this]() { return !queue.empty(); });
            popped = std::move(queue);
            queue.clear();
        }

        for (const T& t : queue) {
        for (const T& t : popped) {
            fn(t);
        }
        queue.clear();
    }
};