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/basictypes.h" | 9 #include "base/basictypes.h" |
10 | 10 |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 #include <windows.h> | 12 #include <windows.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
16 #include <list> | 16 #include <list> |
17 #include <utility> | 17 #include <utility> |
18 #include "base/lock.h" | |
19 #include "base/ref_counted.h" | 18 #include "base/ref_counted.h" |
| 19 #include "base/synchronization/lock.h" |
20 #endif | 20 #endif |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 | 23 |
24 // This replaces INFINITE from Win32 | 24 // This replaces INFINITE from Win32 |
25 static const int kNoTimeout = -1; | 25 static const int kNoTimeout = -1; |
26 | 26 |
27 class TimeDelta; | 27 class TimeDelta; |
28 | 28 |
29 // A WaitableEvent can be a useful thread synchronization tool when you want to | 29 // A WaitableEvent can be a useful thread synchronization tool when you want to |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); | 148 virtual ~WaitableEventKernel(); |
149 | 149 |
150 bool Dequeue(Waiter* waiter, void* tag); | 150 bool Dequeue(Waiter* waiter, void* tag); |
151 | 151 |
152 Lock lock_; | 152 base::Lock lock_; |
153 const bool manual_reset_; | 153 const bool manual_reset_; |
154 bool signaled_; | 154 bool signaled_; |
155 std::list<Waiter*> waiters_; | 155 std::list<Waiter*> waiters_; |
156 }; | 156 }; |
157 | 157 |
158 typedef std::pair<WaitableEvent*, size_t> WaiterAndIndex; | 158 typedef std::pair<WaitableEvent*, size_t> WaiterAndIndex; |
159 | 159 |
160 // When dealing with arrays of WaitableEvent*, we want to sort by the address | 160 // 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. | 161 // 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 | 162 // 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, | 163 // second element is the index of the WaitableEvent in the original, |
164 // unsorted, array. | 164 // unsorted, array. |
165 static size_t EnqueueMany(WaiterAndIndex* waitables, | 165 static size_t EnqueueMany(WaiterAndIndex* waitables, |
166 size_t count, Waiter* waiter); | 166 size_t count, Waiter* waiter); |
167 | 167 |
168 bool SignalAll(); | 168 bool SignalAll(); |
169 bool SignalOne(); | 169 bool SignalOne(); |
170 void Enqueue(Waiter* waiter); | 170 void Enqueue(Waiter* waiter); |
171 | 171 |
172 scoped_refptr<WaitableEventKernel> kernel_; | 172 scoped_refptr<WaitableEventKernel> kernel_; |
173 #endif | 173 #endif |
174 | 174 |
175 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); | 175 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); |
176 }; | 176 }; |
177 | 177 |
178 } // namespace base | 178 } // namespace base |
179 | 179 |
180 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ | 180 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ |
OLD | NEW |