OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ | 5 #ifndef BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ |
6 #define BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ | 6 #define BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/base_export.h" | 9 #include "base/base_export.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~WaitableEventKernel(); | |
149 | 148 |
150 bool Dequeue(Waiter* waiter, void* tag); | 149 bool Dequeue(Waiter* waiter, void* tag); |
151 | 150 |
152 base::Lock lock_; | 151 base::Lock lock_; |
153 const bool manual_reset_; | 152 const bool manual_reset_; |
154 bool signaled_; | 153 bool signaled_; |
155 std::list<Waiter*> waiters_; | 154 std::list<Waiter*> waiters_; |
| 155 |
| 156 private: |
| 157 friend class RefCountedThreadSafe<WaitableEventKernel>; |
| 158 ~WaitableEventKernel(); |
156 }; | 159 }; |
157 | 160 |
158 typedef std::pair<WaitableEvent*, size_t> WaiterAndIndex; | 161 typedef std::pair<WaitableEvent*, size_t> WaiterAndIndex; |
159 | 162 |
160 // When dealing with arrays of WaitableEvent*, we want to sort by the address | 163 // When dealing with arrays of WaitableEvent*, we want to sort by the address |
161 // of the WaitableEvent in order to have a globally consistent locking order. | 164 // of the WaitableEvent in order to have a globally consistent locking order. |
162 // In that case we keep them, in sorted order, in an array of pairs where the | 165 // In that case we keep them, in sorted order, in an array of pairs where the |
163 // second element is the index of the WaitableEvent in the original, | 166 // second element is the index of the WaitableEvent in the original, |
164 // unsorted, array. | 167 // unsorted, array. |
165 static size_t EnqueueMany(WaiterAndIndex* waitables, | 168 static size_t EnqueueMany(WaiterAndIndex* waitables, |
166 size_t count, Waiter* waiter); | 169 size_t count, Waiter* waiter); |
167 | 170 |
168 bool SignalAll(); | 171 bool SignalAll(); |
169 bool SignalOne(); | 172 bool SignalOne(); |
170 void Enqueue(Waiter* waiter); | 173 void Enqueue(Waiter* waiter); |
171 | 174 |
172 scoped_refptr<WaitableEventKernel> kernel_; | 175 scoped_refptr<WaitableEventKernel> kernel_; |
173 #endif | 176 #endif |
174 | 177 |
175 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); | 178 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); |
176 }; | 179 }; |
177 | 180 |
178 } // namespace base | 181 } // namespace base |
179 | 182 |
180 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ | 183 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ |
OLD | NEW |