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

Side by Side Diff: mojo/edk/system/core.cc

Issue 1504733002: Implementation of WaitSet for new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-waitset-implementation
Patch Set: Add gyp rules. Created 5 years 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/system/core.h ('k') | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 7 #include <vector>
8 8
9 #include "base/containers/stack_container.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/rand_util.h" 11 #include "base/rand_util.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "mojo/edk/embedder/embedder_internal.h" 13 #include "mojo/edk/embedder/embedder_internal.h"
13 #include "mojo/edk/embedder/platform_channel_pair.h" 14 #include "mojo/edk/embedder/platform_channel_pair.h"
14 #include "mojo/edk/embedder/platform_shared_buffer.h" 15 #include "mojo/edk/embedder/platform_shared_buffer.h"
15 #include "mojo/edk/embedder/platform_support.h" 16 #include "mojo/edk/embedder/platform_support.h"
16 #include "mojo/edk/system/async_waiter.h" 17 #include "mojo/edk/system/async_waiter.h"
17 #include "mojo/edk/system/broker.h" 18 #include "mojo/edk/system/broker.h"
18 #include "mojo/edk/system/configuration.h" 19 #include "mojo/edk/system/configuration.h"
19 #include "mojo/edk/system/data_pipe.h" 20 #include "mojo/edk/system/data_pipe.h"
20 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" 21 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
21 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" 22 #include "mojo/edk/system/data_pipe_producer_dispatcher.h"
22 #include "mojo/edk/system/dispatcher.h" 23 #include "mojo/edk/system/dispatcher.h"
23 #include "mojo/edk/system/handle_signals_state.h" 24 #include "mojo/edk/system/handle_signals_state.h"
24 #include "mojo/edk/system/message_pipe_dispatcher.h" 25 #include "mojo/edk/system/message_pipe_dispatcher.h"
25 #include "mojo/edk/system/shared_buffer_dispatcher.h" 26 #include "mojo/edk/system/shared_buffer_dispatcher.h"
27 #include "mojo/edk/system/wait_set_dispatcher.h"
26 #include "mojo/edk/system/waiter.h" 28 #include "mojo/edk/system/waiter.h"
27 #include "mojo/public/c/system/macros.h" 29 #include "mojo/public/c/system/macros.h"
28 #include "mojo/public/cpp/system/macros.h" 30 #include "mojo/public/cpp/system/macros.h"
29 31
30 namespace mojo { 32 namespace mojo {
31 namespace edk { 33 namespace edk {
32 34
33 // Implementation notes 35 // Implementation notes
34 // 36 //
35 // Mojo primitives are implemented by the singleton |Core| object. Most calls 37 // Mojo primitives are implemented by the singleton |Core| object. Most calls
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a 172 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a
171 // subclass of |MojoHandleSignalsState| that doesn't add any data members. 173 // subclass of |MojoHandleSignalsState| that doesn't add any data members.
172 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index, 174 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index,
173 reinterpret_cast<HandleSignalsState*>(signals_state)); 175 reinterpret_cast<HandleSignalsState*>(signals_state));
174 } 176 }
175 if (index != static_cast<uint32_t>(-1) && result_index) 177 if (index != static_cast<uint32_t>(-1) && result_index)
176 *result_index = index; 178 *result_index = index;
177 return rv; 179 return rv;
178 } 180 }
179 181
182 MojoResult Core::CreateWaitSet(MojoHandle* wait_set_handle) {
183 if (!wait_set_handle)
184 return MOJO_RESULT_INVALID_ARGUMENT;
185
186 scoped_refptr<WaitSetDispatcher> dispatcher = new WaitSetDispatcher();
187 MojoHandle h = AddDispatcher(dispatcher);
188 if (h == MOJO_HANDLE_INVALID) {
189 LOG(ERROR) << "Handle table full";
190 dispatcher->Close();
191 return MOJO_RESULT_RESOURCE_EXHAUSTED;
192 }
193
194 *wait_set_handle = h;
195 return MOJO_RESULT_OK;
196 }
197
198 MojoResult Core::AddHandle(MojoHandle wait_set_handle,
199 MojoHandle handle,
200 MojoHandleSignals signals) {
201 scoped_refptr<Dispatcher> wait_set_dispatcher(GetDispatcher(wait_set_handle));
202 if (!wait_set_dispatcher)
203 return MOJO_RESULT_INVALID_ARGUMENT;
204
205 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(handle));
206 if (!dispatcher)
207 return MOJO_RESULT_INVALID_ARGUMENT;
208
209 return wait_set_dispatcher->AddWaitingDispatcher(dispatcher, signals, handle);
210 }
211
212 MojoResult Core::RemoveHandle(MojoHandle wait_set_handle,
213 MojoHandle handle) {
214 scoped_refptr<Dispatcher> wait_set_dispatcher(GetDispatcher(wait_set_handle));
215 if (!wait_set_dispatcher)
216 return MOJO_RESULT_INVALID_ARGUMENT;
217
218 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(handle));
219 if (!dispatcher)
220 return MOJO_RESULT_INVALID_ARGUMENT;
221
222 return wait_set_dispatcher->RemoveWaitingDispatcher(dispatcher);
223 }
224
225 MojoResult Core::GetReadyHandles(MojoHandle wait_set_handle,
226 uint32_t* count,
227 MojoHandle* handles,
228 MojoResult* results,
229 MojoHandleSignalsState* signals_state) {
230 if (!handles || !count || !(*count) || !results)
231 return MOJO_RESULT_INVALID_ARGUMENT;
232
233 scoped_refptr<Dispatcher> wait_set_dispatcher(GetDispatcher(wait_set_handle));
234 if (!wait_set_dispatcher)
235 return MOJO_RESULT_INVALID_ARGUMENT;
236
237 DispatcherVector awoken_dispatchers;
238 base::StackVector<uintptr_t, 16> contexts;
239 contexts->assign(*count, MOJO_HANDLE_INVALID);
240
241 MojoResult result = wait_set_dispatcher->GetReadyDispatchers(
242 count, &awoken_dispatchers, results, contexts->data());
243
244 if (result == MOJO_RESULT_OK) {
245 for (size_t i = 0; i < *count; i++) {
246 handles[i] = static_cast<MojoHandle>(contexts[i]);
247 if (signals_state)
248 signals_state[i] = awoken_dispatchers[i]->GetHandleSignalsState();
249 }
250 }
251
252 return result;
253 }
254
180 MojoResult Core::CreateMessagePipe( 255 MojoResult Core::CreateMessagePipe(
181 const MojoCreateMessagePipeOptions* options, 256 const MojoCreateMessagePipeOptions* options,
182 MojoHandle* message_pipe_handle0, 257 MojoHandle* message_pipe_handle0,
183 MojoHandle* message_pipe_handle1) { 258 MojoHandle* message_pipe_handle1) {
184 CHECK(message_pipe_handle0); 259 CHECK(message_pipe_handle0);
185 CHECK(message_pipe_handle1); 260 CHECK(message_pipe_handle1);
186 MojoCreateMessagePipeOptions validated_options = {}; 261 MojoCreateMessagePipeOptions validated_options = {};
187 MojoResult result = 262 MojoResult result =
188 MessagePipeDispatcher::ValidateCreateOptions(options, &validated_options); 263 MessagePipeDispatcher::ValidateCreateOptions(options, &validated_options);
189 if (result != MOJO_RESULT_OK) 264 if (result != MOJO_RESULT_OK)
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 if (signals_states) { 692 if (signals_states) {
618 for (; i < num_handles; i++) 693 for (; i < num_handles; i++)
619 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); 694 signals_states[i] = dispatchers[i]->GetHandleSignalsState();
620 } 695 }
621 696
622 return rv; 697 return rv;
623 } 698 }
624 699
625 } // namespace edk 700 } // namespace edk
626 } // namespace mojo 701 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core.h ('k') | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698