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

Unified Diff: mojo/public/cpp/system/wait.h

Issue 2102903005: Make the mojo::WaitMany() wrapper insist on std::vectors. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/system/wait.h
diff --git a/mojo/public/cpp/system/wait.h b/mojo/public/cpp/system/wait.h
index a3871d524dd8cbc75c84c32ad8708831ba410002..a1846b05428836553cfbe2459112a8e8a76b40af 100644
--- a/mojo/public/cpp/system/wait.h
+++ b/mojo/public/cpp/system/wait.h
@@ -7,7 +7,7 @@
#include <stdint.h>
-#include <cstddef>
+#include <vector>
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/result.h"
@@ -52,18 +52,19 @@ struct WaitManyResult {
uint32_t index;
};
-// |HandleVectorType| and |FlagsVectorType| should be similar enough to
-// |std::vector<Handle>| and |std::vector<MojoHandleSignals>|, respectively:
-// - They should have a (const) |size()| method that returns an unsigned type.
-// - They must provide contiguous storage, with access via (const) reference to
-// that storage provided by a (const) |operator[]()| (by reference).
-template <class HandleVectorType,
- class FlagsVectorType,
- class SignalsStateVectorType>
-inline WaitManyResult WaitMany(const HandleVectorType& handles,
- const FlagsVectorType& signals,
- MojoDeadline deadline,
- SignalsStateVectorType* signals_states) {
+// |HandleType| should be |Handle| or a "trivial" subclass thereof, like
+// |MessagePipeHandle|, etc.
+template <class HandleType>
+inline WaitManyResult WaitMany(
+ const std::vector<HandleType>& handles,
vardhan 2016/06/29 18:02:18 I'm guessing it used to be templated so that it'd
+ const std::vector<MojoHandleSignals>& signals,
+ MojoDeadline deadline,
+ std::vector<MojoHandleSignalsState>* signals_states) {
+ // We rely on being able to treat a vector of |HandleType|s as if it's an
+ // array of |MojoHandle|s.
+ static_assert(sizeof(HandleType) == sizeof(Handle),
+ "HandleType is not the same size as Handle");
+
if (signals.size() != handles.size() ||
(signals_states && signals_states->size() != signals.size()))
return WaitManyResult(MOJO_RESULT_INVALID_ARGUMENT);
@@ -76,41 +77,10 @@ inline WaitManyResult WaitMany(const HandleVectorType& handles,
}
uint32_t result_index = kInvalidWaitManyIndexValue;
- const Handle& first_handle = handles[0];
- const MojoHandleSignals& first_signals = signals[0];
- MojoHandleSignalsState* first_state =
- signals_states ? &(*signals_states)[0] : nullptr;
- MojoResult result =
- MojoWaitMany(reinterpret_cast<const MojoHandle*>(&first_handle),
- &first_signals, static_cast<uint32_t>(handles.size()),
- deadline, &result_index, first_state);
- return WaitManyResult(result, result_index);
-}
-
-// C++ 4.10, regarding pointer conversion, says that an integral null pointer
-// constant can be converted to |std::nullptr_t|. The opposite direction is not
-// allowed.
-template <class HandleVectorType, class FlagsVectorType>
-inline WaitManyResult WaitMany(const HandleVectorType& handles,
- const FlagsVectorType& signals,
- MojoDeadline deadline,
- std::nullptr_t signals_states) {
- if (signals.size() != handles.size())
- return WaitManyResult(MOJO_RESULT_INVALID_ARGUMENT);
- if (handles.size() >= kInvalidWaitManyIndexValue)
- return WaitManyResult(MOJO_RESULT_RESOURCE_EXHAUSTED);
-
- if (handles.size() == 0) {
- return WaitManyResult(
- MojoWaitMany(nullptr, nullptr, 0, deadline, nullptr, nullptr));
- }
-
- uint32_t result_index = kInvalidWaitManyIndexValue;
- const Handle& first_handle = handles[0];
- const MojoHandleSignals& first_signals = signals[0];
MojoResult result = MojoWaitMany(
- reinterpret_cast<const MojoHandle*>(&first_handle), &first_signals,
- static_cast<uint32_t>(handles.size()), deadline, &result_index, nullptr);
+ &handles[0].value(), signals.data(),
+ static_cast<uint32_t>(handles.size()), deadline, &result_index,
+ signals_states ? signals_states->data() : nullptr);
return WaitManyResult(result, result_index);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698