Don't consider a Bluetooth adapter present until it has an address.
[chromium-blink-merge.git] / cc / CCCompletionEvent.h
blob744573319f45ec3dc753f343e94efdc02041d507
1 // Copyright 2011 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.
5 #ifndef CCCompletionEvent_h
6 #define CCCompletionEvent_h
8 #include <wtf/ThreadingPrimitives.h>
10 namespace WebCore {
12 // Used for making blocking calls from one thread to another. Use only when
13 // absolutely certain that doing-so will not lead to a deadlock.
15 // It is safe to destroy this object as soon as wait() returns.
16 class CCCompletionEvent {
17 public:
18 CCCompletionEvent()
20 #ifndef NDEBUG
21 m_waited = false;
22 m_signaled = false;
23 #endif
24 m_mutex.lock();
27 ~CCCompletionEvent()
29 m_mutex.unlock();
30 ASSERT(m_waited);
31 ASSERT(m_signaled);
34 void wait()
36 ASSERT(!m_waited);
37 #ifndef NDEBUG
38 m_waited = true;
39 #endif
40 m_condition.wait(m_mutex);
43 void signal()
45 MutexLocker lock(m_mutex);
46 ASSERT(!m_signaled);
47 #ifndef NDEBUG
48 m_signaled = true;
49 #endif
50 m_condition.signal();
53 private:
54 Mutex m_mutex;
55 ThreadCondition m_condition;
56 #ifndef NDEBUG
57 // Used to assert that wait() and signal() are each called exactly once.
58 bool m_waited;
59 bool m_signaled;
60 #endif
65 #endif