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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/edk/system/core.cc
diff --git a/mojo/edk/system/core.cc b/mojo/edk/system/core.cc
index 1e0bf4e1dfea36ee749036e3cf160316f9d6437e..cfe01fabb156654f01d0bd5ee5b05be09f2e2db1 100644
--- a/mojo/edk/system/core.cc
+++ b/mojo/edk/system/core.cc
@@ -35,6 +35,7 @@
#include "mojo/edk/system/shared_buffer_dispatcher.h"
#include "mojo/edk/system/wait_set_dispatcher.h"
#include "mojo/edk/system/waiter.h"
+#include "mojo/edk/system/watcher_dispatcher.h"
namespace mojo {
namespace edk {
@@ -48,15 +49,6 @@ const uint32_t kMaxHandlesPerMessage = 1024 * 1024;
// pipes too; for now we just use a constant. This only affects bootstrap pipes.
const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL;
-void CallWatchCallback(MojoWatchCallback callback,
- uintptr_t context,
- MojoResult result,
- const HandleSignalsState& signals_state,
- MojoWatchNotificationFlags flags) {
- callback(context, result, static_cast<MojoHandleSignalsState>(signals_state),
- flags);
-}
-
MojoResult MojoPlatformHandleToScopedPlatformHandle(
const MojoPlatformHandle* platform_handle,
ScopedPlatformHandle* out_handle) {
@@ -428,24 +420,50 @@ MojoResult Core::WaitMany(const MojoHandle* handles,
return rv;
}
-MojoResult Core::Watch(MojoHandle handle,
+MojoResult Core::CreateWatcher(MojoWatcherCallback callback,
+ MojoHandle* watcher_handle) {
+ RequestContext request_context;
+ if (!watcher_handle)
+ return MOJO_RESULT_INVALID_ARGUMENT;
+ *watcher_handle = AddDispatcher(new WatcherDispatcher(callback));
+ if (*watcher_handle == MOJO_HANDLE_INVALID)
+ return MOJO_RESULT_RESOURCE_EXHAUSTED;
+ return MOJO_RESULT_OK;
+}
+
+MojoResult Core::Watch(MojoHandle watcher_handle,
+ MojoHandle handle,
MojoHandleSignals signals,
- MojoWatchCallback callback,
uintptr_t context) {
RequestContext request_context;
+ scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle);
+ if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER)
+ return MOJO_RESULT_INVALID_ARGUMENT;
scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle);
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
- return dispatcher->Watch(
- signals, base::Bind(&CallWatchCallback, callback, context), context);
+ return watcher->WatchDispatcher(dispatcher, signals, context);
}
-MojoResult Core::CancelWatch(MojoHandle handle, uintptr_t context) {
+MojoResult Core::CancelWatch(MojoHandle watcher_handle, uintptr_t context) {
RequestContext request_context;
- scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle);
- if (!dispatcher)
+ scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle);
+ if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER)
+ return MOJO_RESULT_INVALID_ARGUMENT;
+ return watcher->CancelWatch(context);
+}
+
+MojoResult Core::ArmWatcher(MojoHandle watcher_handle,
+ uint32_t* num_ready_contexts,
+ uintptr_t* ready_contexts,
+ MojoResult* ready_results,
+ MojoHandleSignalsState* ready_signals_states) {
+ RequestContext request_context;
+ scoped_refptr<Dispatcher> watcher = GetDispatcher(watcher_handle);
+ if (!watcher || watcher->GetType() != Dispatcher::Type::WATCHER)
return MOJO_RESULT_INVALID_ARGUMENT;
- return dispatcher->CancelWatch(context);
+ return watcher->Arm(num_ready_contexts, ready_contexts, ready_results,
+ ready_signals_states);
}
MojoResult Core::AllocMessage(uint32_t num_bytes,

Powered by Google App Engine
This is Rietveld 408576698