| Index: cc/test/thread_blocker.h
|
| diff --git a/cc/test/thread_blocker.h b/cc/test/thread_blocker.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d7ab0b829cf720d3b72f665498ab98b68c6a5a3f
|
| --- /dev/null
|
| +++ b/cc/test/thread_blocker.h
|
| @@ -0,0 +1,42 @@
|
| +// 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.
|
| +
|
| +#ifndef CC_TEST_THREAD_BLOCKER_H_
|
| +#define CC_TEST_THREAD_BLOCKER_H_
|
| +
|
| +#include "base/synchronization/lock.h"
|
| +#include "base/synchronization/waitable_event.h"
|
| +
|
| +namespace cc {
|
| +
|
| +// This class will block inside the Wait() function after BlockWait() has been
|
| +// called until UnblockWait() is called. Because Wait() blocks, the
|
| +// UnblockWait() call must be done from another thread, so this class is safe to
|
| +// use on multiple threads.
|
| +class ThreadBlocker {
|
| + public:
|
| + ThreadBlocker();
|
| + ~ThreadBlocker();
|
| +
|
| + // This will block if BlockWait() has been called until UnblockWait() is
|
| + // called.
|
| + void Wait();
|
| +
|
| + // Makes future calls to Wait() block.
|
| + void BlockWait();
|
| + // Unblocks any current calls to Wait() and prevents future calls from
|
| + // blocking.
|
| + void UnblockWait();
|
| +
|
| + private:
|
| + base::Lock lock_;
|
| + bool should_delay_;
|
| + base::WaitableEvent waiter_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ThreadBlocker);
|
| +};
|
| +
|
| +} // namespace cc
|
| +
|
| +#endif // CC_TEST_THREAD_BLOCKER_H_
|
|
|