| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 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/synchronization/condition_variable.h" | 10 #include "base/synchronization/condition_variable.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // ----------------------------------------------------------------------------- | 84 // ----------------------------------------------------------------------------- |
| 85 class SyncWaiter : public WaitableEvent::Waiter { | 85 class SyncWaiter : public WaitableEvent::Waiter { |
| 86 public: | 86 public: |
| 87 SyncWaiter() | 87 SyncWaiter() |
| 88 : fired_(false), | 88 : fired_(false), |
| 89 signaling_event_(NULL), | 89 signaling_event_(NULL), |
| 90 lock_(), | 90 lock_(), |
| 91 cv_(&lock_) { | 91 cv_(&lock_) { |
| 92 } | 92 } |
| 93 | 93 |
| 94 virtual bool Fire(WaitableEvent* signaling_event) OVERRIDE { | 94 virtual bool Fire(WaitableEvent* signaling_event) override { |
| 95 base::AutoLock locked(lock_); | 95 base::AutoLock locked(lock_); |
| 96 | 96 |
| 97 if (fired_) | 97 if (fired_) |
| 98 return false; | 98 return false; |
| 99 | 99 |
| 100 fired_ = true; | 100 fired_ = true; |
| 101 signaling_event_ = signaling_event; | 101 signaling_event_ = signaling_event; |
| 102 | 102 |
| 103 cv_.Broadcast(); | 103 cv_.Broadcast(); |
| 104 | 104 |
| 105 // Unlike AsyncWaiter objects, SyncWaiter objects are stack-allocated on | 105 // Unlike AsyncWaiter objects, SyncWaiter objects are stack-allocated on |
| 106 // the blocking thread's stack. There is no |delete this;| in Fire. The | 106 // the blocking thread's stack. There is no |delete this;| in Fire. The |
| 107 // SyncWaiter object is destroyed when it goes out of scope. | 107 // SyncWaiter object is destroyed when it goes out of scope. |
| 108 | 108 |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 WaitableEvent* signaling_event() const { | 112 WaitableEvent* signaling_event() const { |
| 113 return signaling_event_; | 113 return signaling_event_; |
| 114 } | 114 } |
| 115 | 115 |
| 116 // --------------------------------------------------------------------------- | 116 // --------------------------------------------------------------------------- |
| 117 // These waiters are always stack allocated and don't delete themselves. Thus | 117 // These waiters are always stack allocated and don't delete themselves. Thus |
| 118 // there's no problem and the ABA tag is the same as the object pointer. | 118 // there's no problem and the ABA tag is the same as the object pointer. |
| 119 // --------------------------------------------------------------------------- | 119 // --------------------------------------------------------------------------- |
| 120 virtual bool Compare(void* tag) OVERRIDE { | 120 virtual bool Compare(void* tag) override { |
| 121 return this == tag; | 121 return this == tag; |
| 122 } | 122 } |
| 123 | 123 |
| 124 // --------------------------------------------------------------------------- | 124 // --------------------------------------------------------------------------- |
| 125 // Called with lock held. | 125 // Called with lock held. |
| 126 // --------------------------------------------------------------------------- | 126 // --------------------------------------------------------------------------- |
| 127 bool fired() const { | 127 bool fired() const { |
| 128 return fired_; | 128 return fired_; |
| 129 } | 129 } |
| 130 | 130 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 return true; | 408 return true; |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 | 411 |
| 412 return false; | 412 return false; |
| 413 } | 413 } |
| 414 | 414 |
| 415 // ----------------------------------------------------------------------------- | 415 // ----------------------------------------------------------------------------- |
| 416 | 416 |
| 417 } // namespace base | 417 } // namespace base |
| OLD | NEW |