| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 BASE_WAITABLE_EVENT_H_ | 5 #ifndef BASE_WAITABLE_EVENT_H_ |
| 6 #define BASE_WAITABLE_EVENT_H_ | 6 #define BASE_WAITABLE_EVENT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 | 10 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // MSDN documentation says that the resulting behaviour is 'undefined', but | 137 // MSDN documentation says that the resulting behaviour is 'undefined', but |
| 138 // it doesn't crash. However, if we were to include the following members | 138 // it doesn't crash. However, if we were to include the following members |
| 139 // directly then, on POSIX, one couldn't use WaitableEventWatcher to watch an | 139 // directly then, on POSIX, one couldn't use WaitableEventWatcher to watch an |
| 140 // event which gets deleted. This mismatch has bitten us several times now, | 140 // event which gets deleted. This mismatch has bitten us several times now, |
| 141 // so we have a kernel of the WaitableEvent, which is reference counted. | 141 // so we have a kernel of the WaitableEvent, which is reference counted. |
| 142 // WaitableEventWatchers may then take a reference and thus match the Windows | 142 // WaitableEventWatchers may then take a reference and thus match the Windows |
| 143 // behaviour. | 143 // behaviour. |
| 144 struct WaitableEventKernel : | 144 struct WaitableEventKernel : |
| 145 public RefCountedThreadSafe<WaitableEventKernel> { | 145 public RefCountedThreadSafe<WaitableEventKernel> { |
| 146 public: | 146 public: |
| 147 WaitableEventKernel(bool manual_reset, bool initially_signaled) | 147 WaitableEventKernel(bool manual_reset, bool initially_signaled); |
| 148 : manual_reset_(manual_reset), | 148 virtual ~WaitableEventKernel(); |
| 149 signaled_(initially_signaled) { | |
| 150 } | |
| 151 | 149 |
| 152 bool Dequeue(Waiter* waiter, void* tag); | 150 bool Dequeue(Waiter* waiter, void* tag); |
| 153 | 151 |
| 154 Lock lock_; | 152 Lock lock_; |
| 155 const bool manual_reset_; | 153 const bool manual_reset_; |
| 156 bool signaled_; | 154 bool signaled_; |
| 157 std::list<Waiter*> waiters_; | 155 std::list<Waiter*> waiters_; |
| 158 }; | 156 }; |
| 159 | 157 |
| 158 struct WaitableEventKernel; |
| 160 scoped_refptr<WaitableEventKernel> kernel_; | 159 scoped_refptr<WaitableEventKernel> kernel_; |
| 161 | 160 |
| 162 bool SignalAll(); | 161 bool SignalAll(); |
| 163 bool SignalOne(); | 162 bool SignalOne(); |
| 164 void Enqueue(Waiter* waiter); | 163 void Enqueue(Waiter* waiter); |
| 165 | 164 |
| 166 // When dealing with arrays of WaitableEvent*, we want to sort by the address | 165 // When dealing with arrays of WaitableEvent*, we want to sort by the address |
| 167 // of the WaitableEvent in order to have a globally consistent locking order. | 166 // of the WaitableEvent in order to have a globally consistent locking order. |
| 168 // In that case we keep them, in sorted order, in an array of pairs where the | 167 // In that case we keep them, in sorted order, in an array of pairs where the |
| 169 // second element is the index of the WaitableEvent in the original, | 168 // second element is the index of the WaitableEvent in the original, |
| 170 // unsorted, array. | 169 // unsorted, array. |
| 171 typedef std::pair<WaitableEvent*, size_t> WaiterAndIndex; | 170 typedef std::pair<WaitableEvent*, size_t> WaiterAndIndex; |
| 172 static size_t EnqueueMany(WaiterAndIndex* waitables, | 171 static size_t EnqueueMany(WaiterAndIndex* waitables, |
| 173 size_t count, Waiter* waiter); | 172 size_t count, Waiter* waiter); |
| 174 #endif | 173 #endif |
| 175 | 174 |
| 176 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); | 175 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); |
| 177 }; | 176 }; |
| 178 | 177 |
| 179 } // namespace base | 178 } // namespace base |
| 180 | 179 |
| 181 #endif // BASE_WAITABLE_EVENT_H_ | 180 #endif // BASE_WAITABLE_EVENT_H_ |
| OLD | NEW |