| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_COMMON_ONE_SHOT_EVENT_H_ | 5 #ifndef EXTENSIONS_COMMON_ONE_SHOT_EVENT_H_ |
| 6 #define EXTENSIONS_COMMON_ONE_SHOT_EVENT_H_ | 6 #define EXTENSIONS_COMMON_ONE_SHOT_EVENT_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // is signaled. If the OneShotEvent is destroyed before it's | 28 // is signaled. If the OneShotEvent is destroyed before it's |
| 29 // signaled, the delayed closures are destroyed without being run. | 29 // signaled, the delayed closures are destroyed without being run. |
| 30 // | 30 // |
| 31 // This class is similar to a WaitableEvent combined with several | 31 // This class is similar to a WaitableEvent combined with several |
| 32 // WaitableEventWatchers, but using it is simpler. | 32 // WaitableEventWatchers, but using it is simpler. |
| 33 // | 33 // |
| 34 // This class is not thread-safe, and must be used from a single thread. | 34 // This class is not thread-safe, and must be used from a single thread. |
| 35 class OneShotEvent { | 35 class OneShotEvent { |
| 36 public: | 36 public: |
| 37 OneShotEvent(); | 37 OneShotEvent(); |
| 38 // Use the following constructor to create an already signaled event. This is |
| 39 // useful if you construct the event on a different thread from where it is |
| 40 // used, in which case it is not possible to call Signal() just after |
| 41 // construction. |
| 42 explicit OneShotEvent(bool signaled); |
| 38 ~OneShotEvent(); | 43 ~OneShotEvent(); |
| 39 | 44 |
| 40 // True if Signal has been called. This function is mostly for | 45 // True if Signal has been called. This function is mostly for |
| 41 // migrating old code; usually calling Post() unconditionally will | 46 // migrating old code; usually calling Post() unconditionally will |
| 42 // result in more readable code. | 47 // result in more readable code. |
| 43 bool is_signaled() const { | 48 bool is_signaled() const { |
| 44 DCHECK(thread_checker_.CalledOnValidThread()); | 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 45 return signaled_; | 50 return signaled_; |
| 46 } | 51 } |
| 47 | 52 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // Optimization note: We could reduce the size of this class to a | 94 // Optimization note: We could reduce the size of this class to a |
| 90 // single pointer by storing |signaled_| in the low bit of a | 95 // single pointer by storing |signaled_| in the low bit of a |
| 91 // pointer, and storing the size and capacity of the array (if any) | 96 // pointer, and storing the size and capacity of the array (if any) |
| 92 // on the far end of the pointer. | 97 // on the far end of the pointer. |
| 93 mutable std::vector<TaskInfo> tasks_; | 98 mutable std::vector<TaskInfo> tasks_; |
| 94 }; | 99 }; |
| 95 | 100 |
| 96 } // namespace extensions | 101 } // namespace extensions |
| 97 | 102 |
| 98 #endif // EXTENSIONS_COMMON_ONE_SHOT_EVENT_H_ | 103 #endif // EXTENSIONS_COMMON_ONE_SHOT_EVENT_H_ |
| OLD | NEW |