| 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" |
| 11 #include "base/time/time.h" |
| 11 | 12 |
| 12 namespace cc { | 13 namespace cc { |
| 13 | 14 |
| 14 // Used for making blocking calls from one thread to another. Use only when | 15 // Used for making blocking calls from one thread to another. Use only when |
| 15 // absolutely certain that doing-so will not lead to a deadlock. | 16 // absolutely certain that doing-so will not lead to a deadlock. |
| 16 // | 17 // |
| 17 // It is safe to destroy this object as soon as Wait() returns. | 18 // It is safe to destroy this object as soon as Wait() returns. |
| 18 class CompletionEvent { | 19 class CompletionEvent { |
| 19 public: | 20 public: |
| 20 CompletionEvent() | 21 CompletionEvent() |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 | 35 |
| 35 void Wait() { | 36 void Wait() { |
| 36 #if DCHECK_IS_ON() | 37 #if DCHECK_IS_ON() |
| 37 DCHECK(!waited_); | 38 DCHECK(!waited_); |
| 38 waited_ = true; | 39 waited_ = true; |
| 39 #endif | 40 #endif |
| 40 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 41 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 41 event_.Wait(); | 42 event_.Wait(); |
| 42 } | 43 } |
| 43 | 44 |
| 45 void TimedWait(const base::TimeDelta& max_time) { |
| 46 #if DCHECK_IS_ON() |
| 47 DCHECK(!waited_); |
| 48 waited_ = true; |
| 49 #endif |
| 50 event_.TimedWait(max_time); |
| 51 } |
| 52 |
| 53 bool IsSignaled() { return event_.IsSignaled(); } |
| 54 |
| 44 void Signal() { | 55 void Signal() { |
| 45 #if DCHECK_IS_ON() | 56 #if DCHECK_IS_ON() |
| 46 DCHECK(!signaled_); | 57 DCHECK(!signaled_); |
| 47 signaled_ = true; | 58 signaled_ = true; |
| 48 #endif | 59 #endif |
| 49 event_.Signal(); | 60 event_.Signal(); |
| 50 } | 61 } |
| 51 | 62 |
| 52 private: | 63 private: |
| 53 base::WaitableEvent event_; | 64 base::WaitableEvent event_; |
| 54 #if DCHECK_IS_ON() | 65 #if DCHECK_IS_ON() |
| 55 // Used to assert that Wait() and Signal() are each called exactly once. | 66 // Used to assert that Wait() and Signal() are each called exactly once. |
| 56 bool waited_; | 67 bool waited_; |
| 57 bool signaled_; | 68 bool signaled_; |
| 58 #endif | 69 #endif |
| 59 }; | 70 }; |
| 60 | 71 |
| 61 } // namespace cc | 72 } // namespace cc |
| 62 | 73 |
| 63 #endif // CC_BASE_COMPLETION_EVENT_H_ | 74 #endif // CC_BASE_COMPLETION_EVENT_H_ |
| OLD | NEW |