| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Provides classes with functionality analogous to (but much more limited than) | 5 // Provides classes with functionality analogous to (but much more limited than) |
| 6 // Chromium's |base::WaitableEvent|, which in turn provides functionality | 6 // Chromium's |base::WaitableEvent|, which in turn provides functionality |
| 7 // analogous to Windows's Event. (Unlike these two, we have separate types for | 7 // analogous to Windows's Event. (Unlike these two, we have separate types for |
| 8 // the manual- and auto-reset versions.) | 8 // the manual- and auto-reset versions.) |
| 9 | 9 |
| 10 #ifndef MOJO_EDK_UTIL_WAITABLE_EVENT_H_ | 10 #ifndef MOJO_EDK_UTIL_WAITABLE_EVENT_H_ |
| 11 #define MOJO_EDK_UTIL_WAITABLE_EVENT_H_ | 11 #define MOJO_EDK_UTIL_WAITABLE_EVENT_H_ |
| 12 | 12 |
| 13 #include "mojo/edk/util/cond_var.h" | 13 #include "mojo/edk/util/cond_var.h" |
| 14 #include "mojo/edk/util/mutex.h" | 14 #include "mojo/edk/util/mutex.h" |
| 15 #include "mojo/edk/util/thread_annotations.h" | 15 #include "mojo/edk/util/thread_annotations.h" |
| 16 #include "mojo/public/cpp/system/macros.h" | 16 #include "mojo/public/cpp/system/macros.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 namespace util { | 19 namespace util { |
| 20 | 20 |
| 21 // AutoResetWaitableEvent ------------------------------------------------------ | 21 // AutoResetWaitableEvent ------------------------------------------------------ |
| 22 | 22 |
| 23 // An event that can be signaled and waited on. This version automatically | 23 // An event that can be signaled and waited on. This version automatically |
| 24 // returns to the unsignaled state after unblocking one waiter. (This is similar | 24 // returns to the unsignaled state after unblocking one waiter. (This is similar |
| 25 // to Windows's auto-reset Event, which is also imitated by Chromium's | 25 // to Windows's auto-reset Event, which is also imitated by Chromium's |
| 26 // auto-reset |base::WaitableEvent|. However, there are some limitations -- see | 26 // auto-reset |base::WaitableEvent|. However, there are some limitations -- see |
| 27 // |Signal()|.) This class is thread-safe. | 27 // |Signal()|.) This class is thread-safe. |
| 28 class AutoResetWaitableEvent { | 28 class AutoResetWaitableEvent final { |
| 29 public: | 29 public: |
| 30 AutoResetWaitableEvent() {} | 30 AutoResetWaitableEvent() {} |
| 31 ~AutoResetWaitableEvent() {} | 31 ~AutoResetWaitableEvent() {} |
| 32 | 32 |
| 33 // Put the event in the signaled state. Exactly one |Wait()| will be unblocked | 33 // Put the event in the signaled state. Exactly one |Wait()| will be unblocked |
| 34 // and the event will be returned to the unsignaled state. | 34 // and the event will be returned to the unsignaled state. |
| 35 // | 35 // |
| 36 // Notes (these are arguably bugs, but not worth working around): | 36 // Notes (these are arguably bugs, but not worth working around): |
| 37 // * That |Wait()| may be one that occurs on the calling thread, *after* the | 37 // * That |Wait()| may be one that occurs on the calling thread, *after* the |
| 38 // call to |Signal()|. | 38 // call to |Signal()|. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 MOJO_DISALLOW_COPY_AND_ASSIGN(AutoResetWaitableEvent); | 71 MOJO_DISALLOW_COPY_AND_ASSIGN(AutoResetWaitableEvent); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // ManualResetWaitableEvent ---------------------------------------------------- | 74 // ManualResetWaitableEvent ---------------------------------------------------- |
| 75 | 75 |
| 76 // An event that can be signaled and waited on. This version remains signaled | 76 // An event that can be signaled and waited on. This version remains signaled |
| 77 // until explicitly reset. (This is similar to Windows's manual-reset Event, | 77 // until explicitly reset. (This is similar to Windows's manual-reset Event, |
| 78 // which is also imitated by Chromium's manual-reset |base::WaitableEvent|.) | 78 // which is also imitated by Chromium's manual-reset |base::WaitableEvent|.) |
| 79 // This class is thread-safe. | 79 // This class is thread-safe. |
| 80 class ManualResetWaitableEvent { | 80 class ManualResetWaitableEvent final { |
| 81 public: | 81 public: |
| 82 ManualResetWaitableEvent() {} | 82 ManualResetWaitableEvent() {} |
| 83 ~ManualResetWaitableEvent() {} | 83 ~ManualResetWaitableEvent() {} |
| 84 | 84 |
| 85 // Put the event into the unsignaled state. | 85 // Put the event into the unsignaled state. |
| 86 void Reset(); | 86 void Reset(); |
| 87 | 87 |
| 88 // Put the event in the signaled state. If this is a manual-reset event, it | 88 // Put the event in the signaled state. If this is a manual-reset event, it |
| 89 // wakes all waiting threads (blocked on |Wait()| or |WaitWithTimeout()|). | 89 // wakes all waiting threads (blocked on |Wait()| or |WaitWithTimeout()|). |
| 90 // Otherwise, it wakes a single waiting thread (and returns to the unsignaled | 90 // Otherwise, it wakes a single waiting thread (and returns to the unsignaled |
| (...skipping 27 matching lines...) Expand all Loading... |
| 118 // was awoken if |signal_id_| is different from when it started waiting. | 118 // was awoken if |signal_id_| is different from when it started waiting. |
| 119 unsigned signal_id_ MOJO_GUARDED_BY(mutex_) = 0u; | 119 unsigned signal_id_ MOJO_GUARDED_BY(mutex_) = 0u; |
| 120 | 120 |
| 121 MOJO_DISALLOW_COPY_AND_ASSIGN(ManualResetWaitableEvent); | 121 MOJO_DISALLOW_COPY_AND_ASSIGN(ManualResetWaitableEvent); |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 } // namespace util | 124 } // namespace util |
| 125 } // namespace mojo | 125 } // namespace mojo |
| 126 | 126 |
| 127 #endif // MOJO_EDK_UTIL_WAITABLE_EVENT_H_ | 127 #endif // MOJO_EDK_UTIL_WAITABLE_EVENT_H_ |
| OLD | NEW |