OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
6 #define MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 6 #define MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
7 | 7 |
8 #include <assert.h> | 8 #include <assert.h> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 template <class HandleVectorType, class FlagsVectorType> | 207 template <class HandleVectorType, class FlagsVectorType> |
208 inline MojoResult WaitMany(const HandleVectorType& handles, | 208 inline MojoResult WaitMany(const HandleVectorType& handles, |
209 const FlagsVectorType& signals, | 209 const FlagsVectorType& signals, |
210 MojoDeadline deadline) { | 210 MojoDeadline deadline) { |
211 if (signals.size() != handles.size()) | 211 if (signals.size() != handles.size()) |
212 return MOJO_RESULT_INVALID_ARGUMENT; | 212 return MOJO_RESULT_INVALID_ARGUMENT; |
213 if (handles.size() > std::numeric_limits<uint32_t>::max()) | 213 if (handles.size() > std::numeric_limits<uint32_t>::max()) |
214 return MOJO_RESULT_OUT_OF_RANGE; | 214 return MOJO_RESULT_OUT_OF_RANGE; |
215 | 215 |
216 if (handles.size() == 0) | 216 if (handles.size() == 0) |
217 return MojoWaitMany(NULL, NULL, 0, deadline); | 217 return MojoWaitMany(nullptr, nullptr, 0, deadline); |
218 | 218 |
219 const Handle& first_handle = handles[0]; | 219 const Handle& first_handle = handles[0]; |
220 const MojoHandleSignals& first_signals = signals[0]; | 220 const MojoHandleSignals& first_signals = signals[0]; |
221 return MojoWaitMany( | 221 return MojoWaitMany( |
222 reinterpret_cast<const MojoHandle*>(&first_handle), | 222 reinterpret_cast<const MojoHandle*>(&first_handle), |
223 reinterpret_cast<const MojoHandleSignals*>(&first_signals), | 223 reinterpret_cast<const MojoHandleSignals*>(&first_signals), |
224 static_cast<uint32_t>(handles.size()), | 224 static_cast<uint32_t>(handles.size()), |
225 deadline); | 225 deadline); |
226 } | 226 } |
227 | 227 |
228 // |Close()| takes ownership of the handle, since it'll invalidate it. | 228 // |Close()| takes ownership of the handle, since it'll invalidate it. |
229 // Note: There's nothing to do, since the argument will be destroyed when it | 229 // Note: There's nothing to do, since the argument will be destroyed when it |
230 // goes out of scope. | 230 // goes out of scope. |
231 template <class HandleType> | 231 template <class HandleType> |
232 inline void Close(ScopedHandleBase<HandleType> /*handle*/) {} | 232 inline void Close(ScopedHandleBase<HandleType> /*handle*/) {} |
233 | 233 |
234 // Most users should typically use |Close()| (above) instead. | 234 // Most users should typically use |Close()| (above) instead. |
235 inline MojoResult CloseRaw(Handle handle) { | 235 inline MojoResult CloseRaw(Handle handle) { |
236 return MojoClose(handle.value()); | 236 return MojoClose(handle.value()); |
237 } | 237 } |
238 | 238 |
239 // Strict weak ordering, so that |Handle|s can be used as keys in |std::map|s, | 239 // Strict weak ordering, so that |Handle|s can be used as keys in |std::map|s, |
240 inline bool operator<(const Handle a, const Handle b) { | 240 inline bool operator<(const Handle a, const Handle b) { |
241 return a.value() < b.value(); | 241 return a.value() < b.value(); |
242 } | 242 } |
243 | 243 |
244 } // namespace mojo | 244 } // namespace mojo |
245 | 245 |
246 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 246 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
OLD | NEW |