Index: mojo/public/cpp/system/event.h |
diff --git a/mojo/public/cpp/system/event.h b/mojo/public/cpp/system/event.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1dca4fea3de9930674e59c78ab81b5a1229b4da7 |
--- /dev/null |
+++ b/mojo/public/cpp/system/event.h |
@@ -0,0 +1,45 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MOJO_PUBLIC_CPP_SYSTEM_EVENT_H_ |
+#define MOJO_PUBLIC_CPP_SYSTEM_EVENT_H_ |
+ |
+#include "base/macros.h" |
+#include "mojo/public/cpp/system/message_pipe.h" |
+ |
+namespace mojo { |
+ |
+// An Event is a simple wrapper around a Mojo message pipe which supports common |
+// WaitableEvent-like methods of Signal() and Reset(). All public methods on |
+// this object are safe to call from any thread as long as the object is still |
+// alive. |
+class Event { |
+ public: |
+ Event(); |
yzshen1
2016/06/07 17:14:51
Please comment on the initial state, whether the s
Ken Rockot(use gerrit already)
2016/06/07 18:02:25
Done
|
+ ~Event(); |
+ |
+ // Gets a Handle that can be waited on for this Event. Waiting may be done |
+ // synchronously via MojoWait (or indirectly via a wait set), or |
+ // asynchronously using a Watcher. When the Event is signaled, this handle |
+ // will have |MOJO_HANDLE_SIGNAL_READABLE| satisfied. |
+ const Handle& GetHandle() const { return wait_handle_.get(); } |
+ |
+ // Ensures that the Handle returned by |GetHandle()| has the |
+ // |MOJO_HANDLE_SIGNAL_READABLE| signal satisfied. |
+ void Signal(); |
+ |
+ // Ensures that the Handle returned by |GetHandle()| does NOT have the |
+ // |MOJO_HANDLE_SIGNAL_READABLE| signal satisfied. |
+ void Reset(); |
+ |
+ private: |
+ ScopedMessagePipeHandle signal_handle_; |
+ ScopedMessagePipeHandle wait_handle_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Event); |
+}; |
+ |
+} // namespace mojo |
+ |
+#endif // MOJO_PUBLIC_CPP_SYSTEM_EVENT_H_ |