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

Unified Diff: mojo/public/cpp/bindings/sync_handle_registry.h

Issue 2754143005: Use WaitableEvents to wake up sync IPC waiting (Closed)
Patch Set: docs 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/public/cpp/bindings/sync_handle_registry.h
diff --git a/mojo/public/cpp/bindings/sync_handle_registry.h b/mojo/public/cpp/bindings/sync_handle_registry.h
index 3cf0492b76a8bb4be2d7a8c3414e990b1a086796..482e3b10e10b634b60bb30b35c65033d7364abf5 100644
--- a/mojo/public/cpp/bindings/sync_handle_registry.h
+++ b/mojo/public/cpp/bindings/sync_handle_registry.h
@@ -5,11 +5,13 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_SYNC_HANDLE_REGISTRY_H_
#define MOJO_PUBLIC_CPP_BINDINGS_SYNC_HANDLE_REGISTRY_H_
+#include <map>
#include <unordered_map>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/synchronization/waitable_event.h"
#include "base/threading/thread_checker.h"
#include "mojo/public/cpp/bindings/bindings_export.h"
#include "mojo/public/cpp/system/core.h"
@@ -34,6 +36,14 @@ class MOJO_CPP_BINDINGS_EXPORT SyncHandleRegistry
void UnregisterHandle(const Handle& handle);
+ // Registers a |base::WaitableEvent| which can be used to wake up
+ // WatchAllHandles() before any handle signals. |event| is not owned, and if
+ // it signals during WatchAllHandles(), |callback| is invoked. Returns |true|
+ // if registered successfully or |false| if |event| was already registered.
+ bool RegisterEvent(base::WaitableEvent* event, const base::Closure& callback);
+
+ void UnregisterEvent(base::WaitableEvent* event);
+
// Waits on all the registered handles and runs callbacks synchronously for
// those ready handles.
// The method:
@@ -57,6 +67,7 @@ class MOJO_CPP_BINDINGS_EXPORT SyncHandleRegistry
HandleMap handles_;
WaitSet wait_set_;
+ std::map<base::WaitableEvent*, base::Closure> events_;
yzshen1 2017/03/23 20:15:50 It is a little weird to use unordered_map for one
Ken Rockot(use gerrit already) 2017/03/23 22:04:20 Done. Based on recent discussions making me feel s
base::ThreadChecker thread_checker_;

Powered by Google App Engine
This is Rietveld 408576698