Chromium Code Reviews| 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 { | |
|
reveman
2014/11/13 20:10:04
What's the difference between an instance of this
danakj
2014/11/13 20:14:17
A nicer API around should_delay_ I think for this
danakj
2014/11/13 20:20:18
Mmm, I guess the test could Reset() instead of Blo
| |
| 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 |