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

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

Issue 2725133002: Mojo: Armed Watchers (Closed)
Patch Set: rebase Created 3 years, 9 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 unified diff | Download patch
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 <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 17 matching lines...) Expand all
28 #include "mojo/edk/system/handle_signals_state.h" 28 #include "mojo/edk/system/handle_signals_state.h"
29 #include "mojo/edk/system/message_for_transit.h" 29 #include "mojo/edk/system/message_for_transit.h"
30 #include "mojo/edk/system/message_pipe_dispatcher.h" 30 #include "mojo/edk/system/message_pipe_dispatcher.h"
31 #include "mojo/edk/system/platform_handle_dispatcher.h" 31 #include "mojo/edk/system/platform_handle_dispatcher.h"
32 #include "mojo/edk/system/ports/name.h" 32 #include "mojo/edk/system/ports/name.h"
33 #include "mojo/edk/system/ports/node.h" 33 #include "mojo/edk/system/ports/node.h"
34 #include "mojo/edk/system/request_context.h" 34 #include "mojo/edk/system/request_context.h"
35 #include "mojo/edk/system/shared_buffer_dispatcher.h" 35 #include "mojo/edk/system/shared_buffer_dispatcher.h"
36 #include "mojo/edk/system/wait_set_dispatcher.h" 36 #include "mojo/edk/system/wait_set_dispatcher.h"
37 #include "mojo/edk/system/waiter.h" 37 #include "mojo/edk/system/waiter.h"
38 #include "mojo/edk/system/watcher_dispatcher.h"
38 39
39 namespace mojo { 40 namespace mojo {
40 namespace edk { 41 namespace edk {
41 42
42 namespace { 43 namespace {
43 44
44 // This is an unnecessarily large limit that is relatively easy to enforce. 45 // This is an unnecessarily large limit that is relatively easy to enforce.
45 const uint32_t kMaxHandlesPerMessage = 1024 * 1024; 46 const uint32_t kMaxHandlesPerMessage = 1024 * 1024;
46 47
47 // TODO(rockot): Maybe we could negotiate a debugging pipe ID for cross-process 48 // TODO(rockot): Maybe we could negotiate a debugging pipe ID for cross-process
48 // pipes too; for now we just use a constant. This only affects bootstrap pipes. 49 // pipes too; for now we just use a constant. This only affects bootstrap pipes.
49 const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL; 50 const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL;
50 51
51 void CallWatchCallback(MojoWatchCallback callback,
52 uintptr_t context,
53 MojoResult result,
54 const HandleSignalsState& signals_state,
55 MojoWatchNotificationFlags flags) {
56 callback(context, result, static_cast<MojoHandleSignalsState>(signals_state),
57 flags);
58 }
59
60 MojoResult MojoPlatformHandleToScopedPlatformHandle( 52 MojoResult MojoPlatformHandleToScopedPlatformHandle(
61 const MojoPlatformHandle* platform_handle, 53 const MojoPlatformHandle* platform_handle,
62 ScopedPlatformHandle* out_handle) { 54 ScopedPlatformHandle* out_handle) {
63 if (platform_handle->struct_size != sizeof(MojoPlatformHandle)) 55 if (platform_handle->struct_size != sizeof(MojoPlatformHandle))
64 return MOJO_RESULT_INVALID_ARGUMENT; 56 return MOJO_RESULT_INVALID_ARGUMENT;
65 57
66 if (platform_handle->type == MOJO_PLATFORM_HANDLE_TYPE_INVALID) { 58 if (platform_handle->type == MOJO_PLATFORM_HANDLE_TYPE_INVALID) {
67 out_handle->reset(); 59 out_handle->reset();
68 return MOJO_RESULT_OK; 60 return MOJO_RESULT_OK;
69 } 61 }
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a 413 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a
422 // subclass of |MojoHandleSignalsState| that doesn't add any data members. 414 // subclass of |MojoHandleSignalsState| that doesn't add any data members.
423 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index, 415 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index,
424 reinterpret_cast<HandleSignalsState*>(signals_state)); 416 reinterpret_cast<HandleSignalsState*>(signals_state));
425 } 417 }
426 if (index != static_cast<uint32_t>(-1) && result_index) 418 if (index != static_cast<uint32_t>(-1) && result_index)
427 *result_index = index; 419 *result_index = index;
428 return rv; 420 return rv;
429 } 421 }
430 422
431 MojoResult Core::Watch(MojoHandle handle, 423 MojoResult Core::CreateWatcher(MojoWatcherCallback callback,
424 MojoHandle* watcher_handle) {
425 RequestContext request_context;
426 if (!watcher_handle)
427 return MOJO_RESULT_INVALID_ARGUMENT;
428 *watcher_handle = AddDispatcher(new WatcherDispatcher(callback));
429 if (*watcher_handle == MOJO_HANDLE_INVALID)
430 return MOJO_RESULT_RESOURCE_EXHAUSTED;
431 return MOJO_RESULT_OK;
432 }
433
434 MojoResult Core::Watch(MojoHandle watcher_handle,
435 MojoHandle handle,
432 MojoHandleSignals signals, 436 MojoHandleSignals signals,
433 MojoWatchCallback callback,
434 uintptr_t context) { 437 uintptr_t context) {
435 RequestContext request_context; 438 RequestContext request_context;
439 scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle);
440 if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER)
441 return MOJO_RESULT_INVALID_ARGUMENT;
436 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); 442 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle);
437 if (!dispatcher) 443 if (!dispatcher)
438 return MOJO_RESULT_INVALID_ARGUMENT; 444 return MOJO_RESULT_INVALID_ARGUMENT;
439 return dispatcher->Watch( 445 return watcher->WatchDispatcher(dispatcher, signals, context);
440 signals, base::Bind(&CallWatchCallback, callback, context), context);
441 } 446 }
442 447
443 MojoResult Core::CancelWatch(MojoHandle handle, uintptr_t context) { 448 MojoResult Core::CancelWatch(MojoHandle watcher_handle, uintptr_t context) {
444 RequestContext request_context; 449 RequestContext request_context;
445 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle); 450 scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle);
446 if (!dispatcher) 451 if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER)
447 return MOJO_RESULT_INVALID_ARGUMENT; 452 return MOJO_RESULT_INVALID_ARGUMENT;
448 return dispatcher->CancelWatch(context); 453 return watcher->CancelWatch(context);
454 }
455
456 MojoResult Core::ArmWatcher(MojoHandle watcher_handle,
457 uint32_t* num_ready_contexts,
458 uintptr_t* ready_contexts,
459 MojoResult* ready_results,
460 MojoHandleSignalsState* ready_signals_states) {
461 RequestContext request_context;
462 scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle);
463 if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER)
464 return MOJO_RESULT_INVALID_ARGUMENT;
465 return watcher->Arm(num_ready_contexts, ready_contexts, ready_results,
466 ready_signals_states);
449 } 467 }
450 468
451 MojoResult Core::AllocMessage(uint32_t num_bytes, 469 MojoResult Core::AllocMessage(uint32_t num_bytes,
452 const MojoHandle* handles, 470 const MojoHandle* handles,
453 uint32_t num_handles, 471 uint32_t num_handles,
454 MojoAllocMessageFlags flags, 472 MojoAllocMessageFlags flags,
455 MojoMessageHandle* message) { 473 MojoMessageHandle* message) {
456 if (!message) 474 if (!message)
457 return MOJO_RESULT_INVALID_ARGUMENT; 475 return MOJO_RESULT_INVALID_ARGUMENT;
458 476
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 std::unique_ptr<NodeController> node_controller) { 1188 std::unique_ptr<NodeController> node_controller) {
1171 // It's OK to leak this reference. At this point we know the IO loop is still 1189 // It's OK to leak this reference. At this point we know the IO loop is still
1172 // running, and we know the NodeController will observe its eventual 1190 // running, and we know the NodeController will observe its eventual
1173 // destruction. This tells the NodeController to delete itself when that 1191 // destruction. This tells the NodeController to delete itself when that
1174 // happens. 1192 // happens.
1175 node_controller.release()->DestroyOnIOThreadShutdown(); 1193 node_controller.release()->DestroyOnIOThreadShutdown();
1176 } 1194 }
1177 1195
1178 } // namespace edk 1196 } // namespace edk
1179 } // namespace mojo 1197 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698