OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CORE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ |
6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ | 6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ |
7 | 7 |
8 #include <assert.h> | 8 #include <assert.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // Should have zero overhead. | 192 // Should have zero overhead. |
193 MOJO_COMPILE_ASSERT(sizeof(Handle) == sizeof(MojoHandle), | 193 MOJO_COMPILE_ASSERT(sizeof(Handle) == sizeof(MojoHandle), |
194 bad_size_for_cpp_Handle); | 194 bad_size_for_cpp_Handle); |
195 | 195 |
196 // The scoper should also impose no more overhead. | 196 // The scoper should also impose no more overhead. |
197 typedef ScopedHandleBase<Handle> ScopedHandle; | 197 typedef ScopedHandleBase<Handle> ScopedHandle; |
198 MOJO_COMPILE_ASSERT(sizeof(ScopedHandle) == sizeof(Handle), | 198 MOJO_COMPILE_ASSERT(sizeof(ScopedHandle) == sizeof(Handle), |
199 bad_size_for_cpp_ScopedHandle); | 199 bad_size_for_cpp_ScopedHandle); |
200 | 200 |
201 inline MojoResult Wait(const Handle& handle, | 201 inline MojoResult Wait(const Handle& handle, |
202 MojoWaitFlags flags, | 202 MojoHandleSignals signals, |
203 MojoDeadline deadline) { | 203 MojoDeadline deadline) { |
204 return MojoWait(handle.value(), flags, deadline); | 204 return MojoWait(handle.value(), signals, deadline); |
205 } | 205 } |
206 | 206 |
207 // |HandleVectorType| and |FlagsVectorType| should be similar enough to | 207 // |HandleVectorType| and |FlagsVectorType| should be similar enough to |
208 // |std::vector<Handle>| and |std::vector<MojoWaitFlags>|, respectively: | 208 // |std::vector<Handle>| and |std::vector<MojoHandleSignals>|, respectively: |
209 // - They should have a (const) |size()| method that returns an unsigned type. | 209 // - They should have a (const) |size()| method that returns an unsigned type. |
210 // - They must provide contiguous storage, with access via (const) reference to | 210 // - They must provide contiguous storage, with access via (const) reference to |
211 // that storage provided by a (const) |operator[]()| (by reference). | 211 // that storage provided by a (const) |operator[]()| (by reference). |
212 template <class HandleVectorType, class FlagsVectorType> | 212 template <class HandleVectorType, class FlagsVectorType> |
213 inline MojoResult WaitMany(const HandleVectorType& handles, | 213 inline MojoResult WaitMany(const HandleVectorType& handles, |
214 const FlagsVectorType& flags, | 214 const FlagsVectorType& signals, |
215 MojoDeadline deadline) { | 215 MojoDeadline deadline) { |
216 if (flags.size() != handles.size()) | 216 if (signals.size() != handles.size()) |
217 return MOJO_RESULT_INVALID_ARGUMENT; | 217 return MOJO_RESULT_INVALID_ARGUMENT; |
218 if (handles.size() > std::numeric_limits<uint32_t>::max()) | 218 if (handles.size() > std::numeric_limits<uint32_t>::max()) |
219 return MOJO_RESULT_OUT_OF_RANGE; | 219 return MOJO_RESULT_OUT_OF_RANGE; |
220 | 220 |
221 if (handles.size() == 0) | 221 if (handles.size() == 0) |
222 return MojoWaitMany(NULL, NULL, 0, deadline); | 222 return MojoWaitMany(NULL, NULL, 0, deadline); |
223 | 223 |
224 const Handle& first_handle = handles[0]; | 224 const Handle& first_handle = handles[0]; |
225 const MojoWaitFlags& first_flag = flags[0]; | 225 const MojoHandleSignals& first_signals = signals[0]; |
226 return MojoWaitMany(reinterpret_cast<const MojoHandle*>(&first_handle), | 226 return MojoWaitMany( |
227 reinterpret_cast<const MojoWaitFlags*>(&first_flag), | 227 reinterpret_cast<const MojoHandle*>(&first_handle), |
228 static_cast<uint32_t>(handles.size()), | 228 reinterpret_cast<const MojoHandleSignals*>(&first_signals), |
229 deadline); | 229 static_cast<uint32_t>(handles.size()), |
| 230 deadline); |
230 } | 231 } |
231 | 232 |
232 // |Close()| takes ownership of the handle, since it'll invalidate it. | 233 // |Close()| takes ownership of the handle, since it'll invalidate it. |
233 // Note: There's nothing to do, since the argument will be destroyed when it | 234 // Note: There's nothing to do, since the argument will be destroyed when it |
234 // goes out of scope. | 235 // goes out of scope. |
235 template <class HandleType> | 236 template <class HandleType> |
236 inline void Close(ScopedHandleBase<HandleType> /*handle*/) {} | 237 inline void Close(ScopedHandleBase<HandleType> /*handle*/) {} |
237 | 238 |
238 // Most users should typically use |Close()| (above) instead. | 239 // Most users should typically use |Close()| (above) instead. |
239 inline MojoResult CloseRaw(Handle handle) { | 240 inline MojoResult CloseRaw(Handle handle) { |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 CreateSharedBuffer(&options, num_bytes, &handle); | 543 CreateSharedBuffer(&options, num_bytes, &handle); |
543 assert(result == MOJO_RESULT_OK); | 544 assert(result == MOJO_RESULT_OK); |
544 } | 545 } |
545 | 546 |
546 inline SharedBuffer::~SharedBuffer() { | 547 inline SharedBuffer::~SharedBuffer() { |
547 } | 548 } |
548 | 549 |
549 } // namespace mojo | 550 } // namespace mojo |
550 | 551 |
551 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ | 552 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ |
OLD | NEW |