OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_TEST_THREAD_BLOCKER_H_ |
| 6 #define CC_TEST_THREAD_BLOCKER_H_ |
| 7 |
| 8 #include "base/synchronization/lock.h" |
| 9 #include "base/synchronization/waitable_event.h" |
| 10 |
| 11 namespace cc { |
| 12 |
| 13 // This class will block inside the Wait() function after BlockWait() has been |
| 14 // called until UnblockWait() is called. Because Wait() blocks, the |
| 15 // UnblockWait() call must be done from another thread, so this class is safe to |
| 16 // use on multiple threads. |
| 17 class ThreadBlocker { |
| 18 public: |
| 19 ThreadBlocker(); |
| 20 ~ThreadBlocker(); |
| 21 |
| 22 // This will block if BlockWait() has been called until UnblockWait() is |
| 23 // called. |
| 24 void Wait(); |
| 25 |
| 26 // Makes future calls to Wait() block. |
| 27 void BlockWait(); |
| 28 // Unblocks any current calls to Wait() and prevents future calls from |
| 29 // blocking. |
| 30 void UnblockWait(); |
| 31 |
| 32 private: |
| 33 base::Lock lock_; |
| 34 bool should_delay_; |
| 35 base::WaitableEvent waiter_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(ThreadBlocker); |
| 38 }; |
| 39 |
| 40 } // namespace cc |
| 41 |
| 42 #endif // CC_TEST_THREAD_BLOCKER_H_ |
OLD | NEW |