OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef MOJO_SERVICES_MEDIA_FRAMEWORK_UTIL_INCIDENT_H_ | 5 #ifndef MOJO_SERVICES_UTIL_CPP_INCIDENT_H_ |
6 #define MOJO_SERVICES_MEDIA_FRAMEWORK_UTIL_INCIDENT_H_ | 6 #define MOJO_SERVICES_UTIL_CPP_INCIDENT_H_ |
7 | 7 |
8 #include <functional> | 8 #include <functional> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 namespace media { | |
15 | 14 |
16 // The Incident class provides a facility for executing code as the consequence | 15 // The Incident class provides a facility for executing code as the consequence |
17 // of some occurrence. This can be useful for building state machines and | 16 // of some occurrence. This can be useful for building state machines and |
18 // otherwise dealing with asynchronous operations. | 17 // otherwise dealing with asynchronous operations. |
19 // | 18 // |
20 // Incident is not a thread-safe class and has no ability to make a thread wait | 19 // Incident is not a thread-safe class and has no ability to make a thread wait |
21 // or to execute code on a particular thread. | 20 // or to execute code on a particular thread. |
22 // | 21 // |
23 // Incidents rely heavily on std::function, so they shouldn't be used in | 22 // Incidents rely heavily on std::function, so they shouldn't be used in |
24 // enormous numbers. | 23 // enormous numbers. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // Calls Occur. This method makes an ThreadsafeIncident convertible to | 137 // Calls Occur. This method makes an ThreadsafeIncident convertible to |
139 // mojo::Callback<void()>. | 138 // mojo::Callback<void()>. |
140 void Run() { Occur(); } | 139 void Run() { Occur(); } |
141 | 140 |
142 private: | 141 private: |
143 mutable base::Lock consequences_lock_; | 142 mutable base::Lock consequences_lock_; |
144 bool occurred_ = false; | 143 bool occurred_ = false; |
145 std::vector<std::function<void()>> consequences_; | 144 std::vector<std::function<void()>> consequences_; |
146 }; | 145 }; |
147 | 146 |
148 } // namespace media | |
149 } // namespace mojo | 147 } // namespace mojo |
150 | 148 |
151 #endif // MOJO_SERVICES_MEDIA_FRAMEWORK_UTIL_INCIDENT_H_ | 149 #endif // MOJO_SERVICES_UTIL_CPP_INCIDENT_H_ |
OLD | NEW |