Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CCCompletionEvent_h | 5 #ifndef CCCompletionEvent_h |
| 6 #define CCCompletionEvent_h | 6 #define CCCompletionEvent_h |
| 7 | 7 |
| 8 #include "base/logging.h" | |
| 8 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 9 | 10 |
| 10 namespace cc { | 11 namespace cc { |
| 11 | 12 |
| 12 // Used for making blocking calls from one thread to another. Use only when | 13 // 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. | 14 // absolutely certain that doing-so will not lead to a deadlock. |
| 14 // | 15 // |
| 15 // It is safe to destroy this object as soon as wait() returns. | 16 // It is safe to destroy this object as soon as wait() returns. |
| 16 class CCCompletionEvent { | 17 class CCCompletionEvent { |
| 17 public: | 18 public: |
| 18 CCCompletionEvent() | 19 CCCompletionEvent() |
| 19 : m_event(false /* manual_reset */, false /* initially_signaled */) | 20 : m_event(false /* manual_reset */, false /* initially_signaled */) |
| 20 { | 21 { |
| 21 #ifndef NDEBUG | |
| 22 m_waited = false; | 22 m_waited = false; |
| 23 m_signaled = false; | 23 m_signaled = false; |
| 24 #endif | |
| 25 } | 24 } |
| 26 | 25 |
| 27 ~CCCompletionEvent() | 26 ~CCCompletionEvent() |
| 28 { | 27 { |
| 29 ASSERT(m_waited); | 28 DCHECK(m_waited); |
| 30 ASSERT(m_signaled); | 29 DCHECK(m_signaled); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void wait() | 32 void wait() |
| 34 { | 33 { |
| 35 ASSERT(!m_waited); | 34 DCHECK(!m_waited); |
| 36 #ifndef NDEBUG | |
| 37 m_waited = true; | 35 m_waited = true; |
| 38 #endif | |
| 39 m_event.Wait(); | 36 m_event.Wait(); |
| 40 } | 37 } |
| 41 | 38 |
| 42 void signal() | 39 void signal() |
| 43 { | 40 { |
| 44 ASSERT(!m_signaled); | 41 DCHECK(!m_signaled); |
| 45 #ifndef NDEBUG | |
| 46 m_signaled = true; | 42 m_signaled = true; |
| 47 #endif | |
| 48 m_event.Signal(); | 43 m_event.Signal(); |
| 49 } | 44 } |
| 50 | 45 |
| 51 private: | 46 private: |
| 52 base::WaitableEvent m_event; | 47 base::WaitableEvent m_event; |
| 53 #ifndef NDEBUG | |
|
slavi
2012/10/12 22:10:13
Maybe change all the #ifndef NDEBUG to #if ENABLE_
danakj
2012/10/12 22:13:20
ENABLE_DCHECK only exists inside base/logging.h Th
| |
| 54 // Used to assert that wait() and signal() are each called exactly once. | 48 // Used to assert that wait() and signal() are each called exactly once. |
| 55 bool m_waited; | 49 bool m_waited; |
| 56 bool m_signaled; | 50 bool m_signaled; |
| 57 #endif | |
| 58 }; | 51 }; |
| 59 | 52 |
| 60 } | 53 } |
| 61 | 54 |
| 62 #endif | 55 #endif |
| OLD | NEW |