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 #include "mojo/edk/system/core.h" | 5 #include "mojo/edk/system/core.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 signals_state.Put(hss); | 250 signals_state.Put(hss); |
251 return result; | 251 return result; |
252 } | 252 } |
253 | 253 |
254 MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles, | 254 MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles, |
255 UserPointer<const MojoHandleSignals> signals, | 255 UserPointer<const MojoHandleSignals> signals, |
256 uint32_t num_handles, | 256 uint32_t num_handles, |
257 MojoDeadline deadline, | 257 MojoDeadline deadline, |
258 UserPointer<uint32_t> result_index, | 258 UserPointer<uint32_t> result_index, |
259 UserPointer<MojoHandleSignalsState> signals_states) { | 259 UserPointer<MojoHandleSignalsState> signals_states) { |
260 if (num_handles < 1) | |
261 return MOJO_RESULT_INVALID_ARGUMENT; | |
262 if (num_handles > GetConfiguration().max_wait_many_num_handles) | 260 if (num_handles > GetConfiguration().max_wait_many_num_handles) |
263 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 261 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
264 | 262 |
| 263 uint64_t index = static_cast<uint64_t>(-1); |
| 264 if (num_handles == 0u) |
| 265 return WaitManyInternal(nullptr, nullptr, 0u, deadline, &index, nullptr); |
| 266 |
265 UserPointer<const MojoHandle>::Reader handles_reader(handles, num_handles); | 267 UserPointer<const MojoHandle>::Reader handles_reader(handles, num_handles); |
266 UserPointer<const MojoHandleSignals>::Reader signals_reader(signals, | 268 UserPointer<const MojoHandleSignals>::Reader signals_reader(signals, |
267 num_handles); | 269 num_handles); |
268 uint64_t index = static_cast<uint64_t>(-1); | |
269 MojoResult result; | 270 MojoResult result; |
270 if (signals_states.IsNull()) { | 271 if (signals_states.IsNull() || num_handles == 0u) { |
271 result = WaitManyInternal(handles_reader.GetPointer(), | 272 result = WaitManyInternal(handles_reader.GetPointer(), |
272 signals_reader.GetPointer(), num_handles, | 273 signals_reader.GetPointer(), num_handles, |
273 deadline, &index, nullptr); | 274 deadline, &index, nullptr); |
274 } else { | 275 } else { |
275 UserPointer<MojoHandleSignalsState>::Writer signals_states_writer( | 276 UserPointer<MojoHandleSignalsState>::Writer signals_states_writer( |
276 signals_states, num_handles); | 277 signals_states, num_handles); |
277 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a | 278 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a |
278 // subclass of |MojoHandleSignalsState| that doesn't add any data members. | 279 // subclass of |MojoHandleSignalsState| that doesn't add any data members. |
279 result = WaitManyInternal( | 280 result = WaitManyInternal( |
280 handles_reader.GetPointer(), signals_reader.GetPointer(), num_handles, | 281 handles_reader.GetPointer(), signals_reader.GetPointer(), num_handles, |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 } | 836 } |
836 | 837 |
837 // Note: We allow |handles| to repeat the same handle multiple times, since | 838 // Note: We allow |handles| to repeat the same handle multiple times, since |
838 // different flags may be specified. | 839 // different flags may be specified. |
839 MojoResult Core::WaitManyInternal(const MojoHandle* handles, | 840 MojoResult Core::WaitManyInternal(const MojoHandle* handles, |
840 const MojoHandleSignals* signals, | 841 const MojoHandleSignals* signals, |
841 uint32_t num_handles, | 842 uint32_t num_handles, |
842 MojoDeadline deadline, | 843 MojoDeadline deadline, |
843 uint64_t* result_index, | 844 uint64_t* result_index, |
844 HandleSignalsState* signals_states) { | 845 HandleSignalsState* signals_states) { |
845 DCHECK_GT(num_handles, 0u); | |
846 DCHECK_EQ(*result_index, static_cast<uint64_t>(-1)); | 846 DCHECK_EQ(*result_index, static_cast<uint64_t>(-1)); |
847 | 847 |
848 DispatcherVector dispatchers; | 848 DispatcherVector dispatchers; |
849 dispatchers.reserve(num_handles); | 849 dispatchers.reserve(num_handles); |
850 | 850 |
851 { | 851 { |
852 MutexLocker locker(&handle_table_mutex_); | 852 MutexLocker locker(&handle_table_mutex_); |
853 for (uint32_t i = 0; i < num_handles; i++) { | 853 for (uint32_t i = 0; i < num_handles; i++) { |
854 if (handles[i] == MOJO_HANDLE_INVALID) { | 854 if (handles[i] == MOJO_HANDLE_INVALID) { |
855 *result_index = i; | 855 *result_index = i; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 if (signals_states) { | 898 if (signals_states) { |
899 for (; i < num_handles; i++) | 899 for (; i < num_handles; i++) |
900 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); | 900 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); |
901 } | 901 } |
902 | 902 |
903 return result; | 903 return result; |
904 } | 904 } |
905 | 905 |
906 } // namespace system | 906 } // namespace system |
907 } // namespace mojo | 907 } // namespace mojo |
OLD | NEW |