Index: cc/test/thread_blocker.cc |
diff --git a/cc/test/thread_blocker.cc b/cc/test/thread_blocker.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f87ca8fd9c0a4e4367c8e6ec087ab1d1c4082f92 |
--- /dev/null |
+++ b/cc/test/thread_blocker.cc |
@@ -0,0 +1,39 @@ |
+// Copyright 2014 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 "cc/test/thread_blocker.h" |
+ |
+#include "base/bind.h" |
+ |
+namespace cc { |
+ |
+ThreadBlocker::ThreadBlocker() |
+ : should_delay_(false), |
+ waiter_(false /* manual_reset */, false /* initially_signaled */) { |
+} |
+ |
+ThreadBlocker::~ThreadBlocker() { |
+} |
+ |
+void ThreadBlocker::Wait() { |
+ { |
+ base::AutoLock lock(lock_); |
+ if (!should_delay_) |
+ return; |
+ } |
+ waiter_.Wait(); |
+} |
+ |
+void ThreadBlocker::BlockWait() { |
+ base::AutoLock lock(lock_); |
+ should_delay_ = true; |
+} |
+ |
+void ThreadBlocker::UnblockWait() { |
+ base::AutoLock lock(lock_); |
+ should_delay_ = false; |
+ waiter_.Signal(); |
+} |
+ |
+} // namespace cc |