| 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..afb3b56bf41b751d7dcbb43bad22116484179206 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,29 +36,30 @@ class MOJO_CPP_BINDINGS_EXPORT SyncHandleRegistry
|
|
|
| void UnregisterHandle(const Handle& handle);
|
|
|
| - // Waits on all the registered handles and runs callbacks synchronously for
|
| - // those ready handles.
|
| + // Registers a |base::WaitableEvent| which can be used to wake up
|
| + // Wait() before any handle signals. |event| is not owned, and if it signals
|
| + // during Wait(), |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 events and runs callbacks
|
| + // synchronously for any that become ready.
|
| // The method:
|
| // - returns true when any element of |should_stop| is set to true;
|
| // - returns false when any error occurs.
|
| - bool WatchAllHandles(const bool* should_stop[], size_t count);
|
| + bool Wait(const bool* should_stop[], size_t count);
|
|
|
| private:
|
| friend class base::RefCounted<SyncHandleRegistry>;
|
|
|
| - struct HandleHasher {
|
| - size_t operator()(const Handle& handle) const {
|
| - return std::hash<uint32_t>()(static_cast<uint32_t>(handle.value()));
|
| - }
|
| - };
|
| - using HandleMap = std::unordered_map<Handle, HandleCallback, HandleHasher>;
|
| -
|
| SyncHandleRegistry();
|
| ~SyncHandleRegistry();
|
|
|
| - HandleMap handles_;
|
| -
|
| WaitSet wait_set_;
|
| + std::map<Handle, HandleCallback> handles_;
|
| + std::map<base::WaitableEvent*, base::Closure> events_;
|
|
|
| base::ThreadChecker thread_checker_;
|
|
|
|
|