| // Copyright 2018 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| #include "util/msg_loop.h" |
| #include "base/logging.h" |
| thread_local MsgLoop* g_current; |
| DCHECK(g_current == nullptr); |
| DCHECK(g_current == this); |
| std::unique_lock<std::mutex> queue_lock(queue_mutex_); |
| notifier_.wait(queue_lock, [this]() { |
| return (!task_queue_.empty()) || should_quit_; |
| task = std::move(task_queue_.front()); |
| void MsgLoop::PostQuit() { |
| base::BindOnce([](MsgLoop* self) { self->should_quit_ = true; }, this)); |
| void MsgLoop::PostTask(Task work) { |
| std::unique_lock<std::mutex> queue_lock(queue_mutex_); |
| task_queue_.emplace(std::move(work)); |
| void MsgLoop::RunUntilIdleForTesting() { |
| for (bool done = false; !done;) { |
| std::unique_lock<std::mutex> queue_lock(queue_mutex_); |
| task = std::move(task_queue_.front()); |
| MsgLoop* MsgLoop::Current() { |