| 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/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "base/logging.h" |
| 10 | 11 |
| 11 namespace cc { | 12 namespace cc { |
| 12 | 13 |
| 13 // Used for making blocking calls from one thread to another. Use only when | 14 // Used for making blocking calls from one thread to another. Use only when |
| 14 // absolutely certain that doing-so will not lead to a deadlock. | 15 // absolutely certain that doing-so will not lead to a deadlock. |
| 15 // | 16 // |
| 16 // It is safe to destroy this object as soon as wait() returns. | 17 // It is safe to destroy this object as soon as wait() returns. |
| 17 class CCCompletionEvent { | 18 class CCCompletionEvent { |
| 18 public: | 19 public: |
| 19 CCCompletionEvent() | 20 CCCompletionEvent() |
| 20 : m_event(false /* manual_reset */, false /* initially_signaled */) | 21 : m_event(false /* manual_reset */, false /* initially_signaled */) |
| 21 { | 22 { |
| 22 #ifndef NDEBUG | 23 #ifndef NDEBUG |
| 23 m_waited = false; | 24 m_waited = false; |
| 24 m_signaled = false; | 25 m_signaled = false; |
| 25 #endif | 26 #endif |
| 26 } | 27 } |
| 27 | 28 |
| 28 ~CCCompletionEvent() | 29 ~CCCompletionEvent() |
| 29 { | 30 { |
| 30 ASSERT(m_waited); | 31 #ifndef NDEBUG |
| 31 ASSERT(m_signaled); | 32 DCHECK(m_waited); |
| 33 DCHECK(m_signaled); |
| 34 #endif |
| 32 } | 35 } |
| 33 | 36 |
| 34 void wait() | 37 void wait() |
| 35 { | 38 { |
| 36 ASSERT(!m_waited); | |
| 37 #ifndef NDEBUG | 39 #ifndef NDEBUG |
| 40 DCHECK(!m_waited); |
| 38 m_waited = true; | 41 m_waited = true; |
| 39 #endif | 42 #endif |
| 40 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 43 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 41 m_event.Wait(); | 44 m_event.Wait(); |
| 42 } | 45 } |
| 43 | 46 |
| 44 void signal() | 47 void signal() |
| 45 { | 48 { |
| 46 ASSERT(!m_signaled); | |
| 47 #ifndef NDEBUG | 49 #ifndef NDEBUG |
| 50 DCHECK(!m_signaled); |
| 48 m_signaled = true; | 51 m_signaled = true; |
| 49 #endif | 52 #endif |
| 50 m_event.Signal(); | 53 m_event.Signal(); |
| 51 } | 54 } |
| 52 | 55 |
| 53 private: | 56 private: |
| 54 base::WaitableEvent m_event; | 57 base::WaitableEvent m_event; |
| 55 #ifndef NDEBUG | 58 #ifndef NDEBUG |
| 56 // Used to assert that wait() and signal() are each called exactly once. | 59 // Used to assert that wait() and signal() are each called exactly once. |
| 57 bool m_waited; | 60 bool m_waited; |
| 58 bool m_signaled; | 61 bool m_signaled; |
| 59 #endif | 62 #endif |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 } | 65 } |
| 63 | 66 |
| 64 #endif | 67 #endif |
| OLD | NEW |