Mojo: Modify plumbing for the WaitMany implementation.

We'll need this for the new and improved WaitMany.

R=darin@chromium.org

Review URL: https://codereview.chromium.org/419613003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285552 0039d316-1c4b-4281-b951-d872f2087c98
parent 30bb2810
...@@ -120,7 +120,8 @@ MojoResult Core::Close(MojoHandle handle) { ...@@ -120,7 +120,8 @@ MojoResult Core::Close(MojoHandle handle) {
MojoResult Core::Wait(MojoHandle handle, MojoResult Core::Wait(MojoHandle handle,
MojoHandleSignals signals, MojoHandleSignals signals,
MojoDeadline deadline) { MojoDeadline deadline) {
return WaitManyInternal(&handle, &signals, 1, deadline); uint32_t unused = static_cast<uint32_t>(-1);
return WaitManyInternal(&handle, &signals, 1, deadline, &unused);
} }
MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles, MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles,
...@@ -131,11 +132,16 @@ MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles, ...@@ -131,11 +132,16 @@ MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles,
return MOJO_RESULT_INVALID_ARGUMENT; return MOJO_RESULT_INVALID_ARGUMENT;
if (num_handles > kMaxWaitManyNumHandles) if (num_handles > kMaxWaitManyNumHandles)
return MOJO_RESULT_RESOURCE_EXHAUSTED; return MOJO_RESULT_RESOURCE_EXHAUSTED;
UserPointer<const MojoHandle>::Reader handles_reader(handles, num_handles); UserPointer<const MojoHandle>::Reader handles_reader(handles, num_handles);
UserPointer<const MojoHandleSignals>::Reader signals_reader(signals, UserPointer<const MojoHandleSignals>::Reader signals_reader(signals,
num_handles); num_handles);
return WaitManyInternal(handles_reader.GetPointer(), uint32_t result_index = static_cast<uint32_t>(-1);
signals_reader.GetPointer(), num_handles, deadline); MojoResult result = WaitManyInternal(handles_reader.GetPointer(),
signals_reader.GetPointer(), num_handles,
deadline, &result_index);
return (result == MOJO_RESULT_OK) ? static_cast<MojoResult>(result_index) :
result;
} }
MojoResult Core::CreateMessagePipe( MojoResult Core::CreateMessagePipe(
...@@ -516,15 +522,19 @@ MojoResult Core::UnmapBuffer(UserPointerValue<void> buffer) { ...@@ -516,15 +522,19 @@ MojoResult Core::UnmapBuffer(UserPointerValue<void> buffer) {
MojoResult Core::WaitManyInternal(const MojoHandle* handles, MojoResult Core::WaitManyInternal(const MojoHandle* handles,
const MojoHandleSignals* signals, const MojoHandleSignals* signals,
uint32_t num_handles, uint32_t num_handles,
MojoDeadline deadline) { MojoDeadline deadline,
uint32_t* result_index) {
DCHECK_GT(num_handles, 0u); DCHECK_GT(num_handles, 0u);
DCHECK_EQ(*result_index, static_cast<uint32_t>(-1));
DispatcherVector dispatchers; DispatcherVector dispatchers;
dispatchers.reserve(num_handles); dispatchers.reserve(num_handles);
for (uint32_t i = 0; i < num_handles; i++) { for (uint32_t i = 0; i < num_handles; i++) {
scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handles[i]); scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handles[i]);
if (!dispatcher) if (!dispatcher) {
*result_index = i;
return MOJO_RESULT_INVALID_ARGUMENT; return MOJO_RESULT_INVALID_ARGUMENT;
}
dispatchers.push_back(dispatcher); dispatchers.push_back(dispatcher);
} }
...@@ -536,19 +546,17 @@ MojoResult Core::WaitManyInternal(const MojoHandle* handles, ...@@ -536,19 +546,17 @@ MojoResult Core::WaitManyInternal(const MojoHandle* handles,
MojoResult rv = MOJO_RESULT_OK; MojoResult rv = MOJO_RESULT_OK;
for (i = 0; i < num_handles; i++) { for (i = 0; i < num_handles; i++) {
rv = dispatchers[i]->AddWaiter(&waiter, signals[i], i); rv = dispatchers[i]->AddWaiter(&waiter, signals[i], i);
if (rv != MOJO_RESULT_OK) if (rv != MOJO_RESULT_OK) {
*result_index = i;
break; break;
}
} }
uint32_t num_added = i; uint32_t num_added = i;
if (rv == MOJO_RESULT_ALREADY_EXISTS) { if (rv == MOJO_RESULT_ALREADY_EXISTS)
rv = static_cast<MojoResult>(i); // The i-th one is already "triggered". rv = MOJO_RESULT_OK; // The i-th one is already "triggered".
} else if (rv == MOJO_RESULT_OK) { else if (rv == MOJO_RESULT_OK)
uint32_t context = static_cast<uint32_t>(-1); rv = waiter.Wait(deadline, result_index);
rv = waiter.Wait(deadline, &context);
if (rv == MOJO_RESULT_OK)
rv = static_cast<MojoResult>(context);
}
// Make sure no other dispatchers try to wake |waiter| for the current // Make sure no other dispatchers try to wake |waiter| for the current
// |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be
......
...@@ -108,11 +108,14 @@ class MOJO_SYSTEM_IMPL_EXPORT Core { ...@@ -108,11 +108,14 @@ class MOJO_SYSTEM_IMPL_EXPORT Core {
friend bool internal::ShutdownCheckNoLeaks(Core*); friend bool internal::ShutdownCheckNoLeaks(Core*);
// Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic
// validation of arguments. // validation of arguments. |*result_index| is only set if the result (whether
// success or failure) applies to a specific handle, so its value should be
// preinitialized to |static_cast<uint32_t>(-1)|.
MojoResult WaitManyInternal(const MojoHandle* handles, MojoResult WaitManyInternal(const MojoHandle* handles,
const MojoHandleSignals* signals, const MojoHandleSignals* signals,
uint32_t num_handles, uint32_t num_handles,
MojoDeadline deadline); MojoDeadline deadline,
uint32_t* result_index);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment