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

Unified Diff: mojo/public/cpp/system/wait_set.h

Issue 2754143005: Use WaitableEvents to wake up sync IPC waiting (Closed)
Patch Set: . 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
« no previous file with comments | « mojo/public/cpp/system/tests/wait_set_unittest.cc ('k') | mojo/public/cpp/system/wait_set.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/system/wait_set.h
diff --git a/mojo/public/cpp/system/wait_set.h b/mojo/public/cpp/system/wait_set.h
index a7828f7c694c452124c338e9024190d87ac89145..5047a86a4809a8874b252514cc41cb87cb0017af 100644
--- a/mojo/public/cpp/system/wait_set.h
+++ b/mojo/public/cpp/system/wait_set.h
@@ -14,24 +14,45 @@
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/system_export.h"
+namespace base {
+class WaitableEvent;
+}
+
namespace mojo {
// WaitSet provides an efficient means of blocking a thread on any number of
-// Mojo handles changing state in some interesting way.
+// events and Mojo handle state changes.
//
// Unlike WaitMany(), which incurs some extra setup cost for every call, a
-// WaitSet maintains some persistent accounting of a set of handles which can be
-// added or removed from the set. A blocking wait operation (see the Wait()
-// method below) can then be performed multiple times for the same set of
-// handles with minimal additional setup per call.
+// WaitSet maintains some persistent accounting of the handles added or removed
+// from the set. A blocking wait operation (see the Wait() method below) can
+// then be performed multiple times for the same set of events and handles with
+// minimal additional setup per call.
//
-// WaitSet is NOT thread-safe, so naturally handles may not be added to or
-// removed from the set while waiting.
+// WaitSet is NOT thread-safe, so naturally handles and events may not be added
+// to or removed from the set while waiting.
class MOJO_CPP_SYSTEM_EXPORT WaitSet {
public:
WaitSet();
~WaitSet();
+ // Adds |event| to the set of events to wait on. If successful, any future
+ // Wait() on this WaitSet will wake up if the event is signaled.
+ //
+ // |event| is not owned.
+ //
+ // Return values:
+ // |MOJO_RESULT_OK| if |event| has been successfully added.
+ // |MOJO_RESULT_ALREADY_EXISTS| if |event| is already in this WaitSet.
+ MojoResult AddEvent(base::WaitableEvent* event);
+
+ // Removes |event| from the set of events to wait on.
+ //
+ // Return values:
+ // |MOJO_RESULT_OK| if |event| has been successfully added.
+ // |MOJO_RESULT_NOT_FOUND| if |event| was not in the set.
+ MojoResult RemoveEvent(base::WaitableEvent* event);
+
// Adds |handle| to the set of handles to wait on. If successful, any future
// Wait() on this WaitSet will wake up in the event that one or more signals
// in |signals| becomes satisfied on |handle| or all of them become
@@ -51,8 +72,9 @@ class MOJO_CPP_SYSTEM_EXPORT WaitSet {
// |MOJO_RESULT_NOT_FOUND| if |handle| was not in the set.
MojoResult RemoveHandle(Handle handle);
- // Waits on the current set of handles for one or more of them to meet the
- // conditions which were specified when they were added via AddHandle() above.
+ // Waits on the current set of handles, waking up when one more of them meets
+ // the signaling conditions which were specified when they were added via
+ // AddHandle() above.
//
// |*num_ready_handles| on input must specify the number of entries available
// for output storage in |ready_handles| and |ready_result| (which must both
@@ -62,6 +84,12 @@ class MOJO_CPP_SYSTEM_EXPORT WaitSet {
// Upon return, |*num_ready_handles| will contain the total number of handles
// whose information is stored in the given output buffers.
//
+ // If |ready_event| is non-null and the Wait() was unblocked by a user event
+ // signaling, the address of the event which signaled will be placed in
+ // |*ready_event|. Note that this is not necessarily exclusive to one or more
+ // handles also being ready. If |ready_event| is non-null and no user event
+ // was signaled for this Wait(), |*ready_event| will be null upon return.
+ //
// Every entry in |ready_handles| on output corresponds to one of the handles
// whose signaling state termianted the Wait() operation. Every corresponding
// entry in |ready_results| indicates the status of a ready handle according
@@ -75,7 +103,8 @@ class MOJO_CPP_SYSTEM_EXPORT WaitSet {
// but referring to a different handle (i.e. has already been reused) by
// the time Wait() returns. The handle in question is automatically
// removed from the WaitSet.
- void Wait(size_t* num_ready_handles,
+ void Wait(base::WaitableEvent** ready_event,
+ size_t* num_ready_handles,
Handle* ready_handles,
MojoResult* ready_results,
MojoHandleSignalsState* signals_states = nullptr);
« no previous file with comments | « mojo/public/cpp/system/tests/wait_set_unittest.cc ('k') | mojo/public/cpp/system/wait_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698