Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: base/synchronization/waitable_event.h

Issue 593973002: Use ScopedHandle for the private members of WaitableEvent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/synchronization/waitable_event_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #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 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
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 "base/win/scoped_handle.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/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
20 #endif 20 #endif
21 21
22 namespace base { 22 namespace base {
(...skipping 23 matching lines...) Expand all
46 // If manual_reset is true, then to set the event state to non-signaled, a 46 // If manual_reset is true, then to set the event state to non-signaled, a
47 // consumer must call the Reset method. If this parameter is false, then the 47 // consumer must call the Reset method. If this parameter is false, then the
48 // system automatically resets the event state to non-signaled after a single 48 // system automatically resets the event state to non-signaled after a single
49 // waiting thread has been released. 49 // waiting thread has been released.
50 WaitableEvent(bool manual_reset, bool initially_signaled); 50 WaitableEvent(bool manual_reset, bool initially_signaled);
51 51
52 #if defined(OS_WIN) 52 #if defined(OS_WIN)
53 // Create a WaitableEvent from an Event HANDLE which has already been 53 // Create a WaitableEvent from an Event HANDLE which has already been
54 // created. This objects takes ownership of the HANDLE and will close it when 54 // created. This objects takes ownership of the HANDLE and will close it when
55 // deleted. 55 // deleted.
56 // TODO(rvargas): Pass ScopedHandle instead (and on Release).
56 explicit WaitableEvent(HANDLE event_handle); 57 explicit WaitableEvent(HANDLE event_handle);
57 58
58 // Releases ownership of the handle from this object. 59 // Releases ownership of the handle from this object.
59 HANDLE Release(); 60 HANDLE Release();
60 #endif 61 #endif
61 62
62 ~WaitableEvent(); 63 ~WaitableEvent();
63 64
64 // Put the event in the un-signaled state. 65 // Put the event in the un-signaled state.
65 void Reset(); 66 void Reset();
(...skipping 17 matching lines...) Expand all
83 void Wait(); 84 void Wait();
84 85
85 // Wait up until max_time has passed for the event to be signaled. Returns 86 // Wait up until max_time has passed for the event to be signaled. Returns
86 // true if the event was signaled. If this method returns false, then it 87 // true if the event was signaled. If this method returns false, then it
87 // does not necessarily mean that max_time was exceeded. 88 // does not necessarily mean that max_time was exceeded.
88 // 89 //
89 // TimedWait can synchronise its own destruction like |Wait|. 90 // TimedWait can synchronise its own destruction like |Wait|.
90 bool TimedWait(const TimeDelta& max_time); 91 bool TimedWait(const TimeDelta& max_time);
91 92
92 #if defined(OS_WIN) 93 #if defined(OS_WIN)
93 HANDLE handle() const { return handle_; } 94 HANDLE handle() const { return handle_.Get(); }
94 #endif 95 #endif
95 96
96 // Wait, synchronously, on multiple events. 97 // Wait, synchronously, on multiple events.
97 // waitables: an array of WaitableEvent pointers 98 // waitables: an array of WaitableEvent pointers
98 // count: the number of elements in @waitables 99 // count: the number of elements in @waitables
99 // 100 //
100 // returns: the index of a WaitableEvent which has been signaled. 101 // returns: the index of a WaitableEvent which has been signaled.
101 // 102 //
102 // You MUST NOT delete any of the WaitableEvent objects while this wait is 103 // You MUST NOT delete any of the WaitableEvent objects while this wait is
103 // happening, however WaitMany's return "happens after" the |Signal| call 104 // happening, however WaitMany's return "happens after" the |Signal| call
(...skipping 29 matching lines...) Expand all
133 virtual bool Compare(void* tag) = 0; 134 virtual bool Compare(void* tag) = 0;
134 135
135 protected: 136 protected:
136 virtual ~Waiter() {} 137 virtual ~Waiter() {}
137 }; 138 };
138 139
139 private: 140 private:
140 friend class WaitableEventWatcher; 141 friend class WaitableEventWatcher;
141 142
142 #if defined(OS_WIN) 143 #if defined(OS_WIN)
143 HANDLE handle_; 144 win::ScopedHandle handle_;
144 #else 145 #else
145 // On Windows, one can close a HANDLE which is currently being waited on. The 146 // On Windows, one can close a HANDLE which is currently being waited on. The
146 // MSDN documentation says that the resulting behaviour is 'undefined', but 147 // MSDN documentation says that the resulting behaviour is 'undefined', but
147 // it doesn't crash. However, if we were to include the following members 148 // it doesn't crash. However, if we were to include the following members
148 // directly then, on POSIX, one couldn't use WaitableEventWatcher to watch an 149 // directly then, on POSIX, one couldn't use WaitableEventWatcher to watch an
149 // event which gets deleted. This mismatch has bitten us several times now, 150 // event which gets deleted. This mismatch has bitten us several times now,
150 // so we have a kernel of the WaitableEvent, which is reference counted. 151 // so we have a kernel of the WaitableEvent, which is reference counted.
151 // WaitableEventWatchers may then take a reference and thus match the Windows 152 // WaitableEventWatchers may then take a reference and thus match the Windows
152 // behaviour. 153 // behaviour.
153 struct WaitableEventKernel : 154 struct WaitableEventKernel :
(...skipping 29 matching lines...) Expand all
183 184
184 scoped_refptr<WaitableEventKernel> kernel_; 185 scoped_refptr<WaitableEventKernel> kernel_;
185 #endif 186 #endif
186 187
187 DISALLOW_COPY_AND_ASSIGN(WaitableEvent); 188 DISALLOW_COPY_AND_ASSIGN(WaitableEvent);
188 }; 189 };
189 190
190 } // namespace base 191 } // namespace base
191 192
192 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_ 193 #endif // BASE_SYNCHRONIZATION_WAITABLE_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | base/synchronization/waitable_event_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698