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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 // Should have zero overhead. | 187 // Should have zero overhead. |
188 MOJO_COMPILE_ASSERT(sizeof(Handle) == sizeof(MojoHandle), | 188 MOJO_COMPILE_ASSERT(sizeof(Handle) == sizeof(MojoHandle), |
189 bad_size_for_cpp_Handle); | 189 bad_size_for_cpp_Handle); |
190 | 190 |
191 // The scoper should also impose no more overhead. | 191 // The scoper should also impose no more overhead. |
192 typedef ScopedHandleBase<Handle> ScopedHandle; | 192 typedef ScopedHandleBase<Handle> ScopedHandle; |
193 MOJO_COMPILE_ASSERT(sizeof(ScopedHandle) == sizeof(Handle), | 193 MOJO_COMPILE_ASSERT(sizeof(ScopedHandle) == sizeof(Handle), |
194 bad_size_for_cpp_ScopedHandle); | 194 bad_size_for_cpp_ScopedHandle); |
195 | 195 |
196 inline MojoResult Wait(const Handle& handle, | 196 inline MojoResult Wait(Handle handle, |
197 MojoHandleSignals signals, | 197 MojoHandleSignals signals, |
198 MojoDeadline deadline) { | 198 MojoDeadline deadline) { |
199 return MojoWait(handle.value(), signals, deadline); | 199 return MojoWait(handle.value(), signals, deadline); |
200 } | 200 } |
201 | 201 |
202 // |HandleVectorType| and |FlagsVectorType| should be similar enough to | 202 // |HandleVectorType| and |FlagsVectorType| should be similar enough to |
203 // |std::vector<Handle>| and |std::vector<MojoHandleSignals>|, respectively: | 203 // |std::vector<Handle>| and |std::vector<MojoHandleSignals>|, respectively: |
204 // - They should have a (const) |size()| method that returns an unsigned type. | 204 // - They should have a (const) |size()| method that returns an unsigned type. |
205 // - They must provide contiguous storage, with access via (const) reference to | 205 // - They must provide contiguous storage, with access via (const) reference to |
206 // that storage provided by a (const) |operator[]()| (by reference). | 206 // that storage provided by a (const) |operator[]()| (by reference). |
(...skipping 23 matching lines...) Expand all Loading... |
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 // etc. | 240 inline bool operator<(const Handle a, const Handle b) { |
241 inline bool operator<(const Handle& a, const Handle& b) { | |
242 return a.value() < b.value(); | 241 return a.value() < b.value(); |
243 } | 242 } |
244 | 243 |
245 } // namespace mojo | 244 } // namespace mojo |
246 | 245 |
247 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 246 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
OLD | NEW |