| 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 CC_BASE_COMPLETION_EVENT_H_ | 5 #ifndef CC_BASE_COMPLETION_EVENT_H_ |
| 6 #define CC_BASE_COMPLETION_EVENT_H_ | 6 #define CC_BASE_COMPLETION_EVENT_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 void Wait() { | 37 void Wait() { |
| 38 #if DCHECK_IS_ON() | 38 #if DCHECK_IS_ON() |
| 39 DCHECK(!waited_); | 39 DCHECK(!waited_); |
| 40 waited_ = true; | 40 waited_ = true; |
| 41 #endif | 41 #endif |
| 42 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 42 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 43 event_.Wait(); | 43 event_.Wait(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void TimedWait(const base::TimeDelta& max_time) { | 46 bool TimedWait(const base::TimeDelta& max_time) { |
| 47 #if DCHECK_IS_ON() | 47 #if DCHECK_IS_ON() |
| 48 DCHECK(!waited_); | 48 DCHECK(!waited_); |
| 49 waited_ = true; | 49 waited_ = true; |
| 50 #endif | 50 #endif |
| 51 event_.TimedWait(max_time); | 51 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 52 return event_.TimedWait(max_time); |
| 52 } | 53 } |
| 53 | 54 |
| 54 bool IsSignaled() { return event_.IsSignaled(); } | 55 bool IsSignaled() { return event_.IsSignaled(); } |
| 55 | 56 |
| 56 void Signal() { | 57 void Signal() { |
| 57 #if DCHECK_IS_ON() | 58 #if DCHECK_IS_ON() |
| 58 DCHECK(!signaled_); | 59 DCHECK(!signaled_); |
| 59 signaled_ = true; | 60 signaled_ = true; |
| 60 #endif | 61 #endif |
| 61 event_.Signal(); | 62 event_.Signal(); |
| 62 } | 63 } |
| 63 | 64 |
| 64 private: | 65 private: |
| 65 base::WaitableEvent event_; | 66 base::WaitableEvent event_; |
| 66 #if DCHECK_IS_ON() | 67 #if DCHECK_IS_ON() |
| 67 // Used to assert that Wait() and Signal() are each called exactly once. | 68 // Used to assert that Wait() and Signal() are each called exactly once. |
| 68 bool waited_; | 69 bool waited_; |
| 69 bool signaled_; | 70 bool signaled_; |
| 70 #endif | 71 #endif |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 } // namespace cc | 74 } // namespace cc |
| 74 | 75 |
| 75 #endif // CC_BASE_COMPLETION_EVENT_H_ | 76 #endif // CC_BASE_COMPLETION_EVENT_H_ |
| OLD | NEW |