OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void AsyncInvokeDelayed(const Location& posted_from, | 93 void AsyncInvokeDelayed(const Location& posted_from, |
94 Thread* thread, | 94 Thread* thread, |
95 const FunctorT& functor, | 95 const FunctorT& functor, |
96 uint32_t delay_ms, | 96 uint32_t delay_ms, |
97 uint32_t id = 0) { | 97 uint32_t id = 0) { |
98 std::unique_ptr<AsyncClosure> closure( | 98 std::unique_ptr<AsyncClosure> closure( |
99 new FireAndForgetAsyncClosure<FunctorT>(this, functor)); | 99 new FireAndForgetAsyncClosure<FunctorT>(this, functor)); |
100 DoInvokeDelayed(posted_from, thread, std::move(closure), delay_ms, id); | 100 DoInvokeDelayed(posted_from, thread, std::move(closure), delay_ms, id); |
101 } | 101 } |
102 | 102 |
103 // Call |functor| asynchronously on |thread|, calling |callback| when done. | |
104 // Uses a separate Location for |callback_posted_from| so that the functor | |
105 // invoke and the callback invoke can be differentiated. | |
106 template <class ReturnT, class FunctorT, class HostT> | |
107 void AsyncInvoke(const Location& posted_from, | |
108 const Location& callback_posted_from, | |
109 Thread* thread, | |
110 const FunctorT& functor, | |
111 void (HostT::*callback)(ReturnT), | |
112 HostT* callback_host, | |
113 uint32_t id = 0) { | |
114 std::unique_ptr<AsyncClosure> closure( | |
115 new NotifyingAsyncClosure<ReturnT, FunctorT, HostT>( | |
116 this, callback_posted_from, Thread::Current(), functor, callback, | |
117 callback_host)); | |
118 DoInvoke(posted_from, thread, std::move(closure), id); | |
119 } | |
120 | |
121 // Call |functor| asynchronously on |thread|, calling |callback| when done. | |
122 // Uses a separate Location for |callback_posted_from| so that the functor | |
123 // invoke and the callback invoke can be differentiated. | |
124 // Overloaded for void return. | |
125 template <class ReturnT, class FunctorT, class HostT> | |
126 void AsyncInvoke(const Location& posted_from, | |
127 const Location& callback_posted_from, | |
128 Thread* thread, | |
129 const FunctorT& functor, | |
130 void (HostT::*callback)(), | |
131 HostT* callback_host, | |
132 uint32_t id = 0) { | |
133 std::unique_ptr<AsyncClosure> closure( | |
134 new NotifyingAsyncClosure<void, FunctorT, HostT>( | |
135 this, callback_posted_from, Thread::Current(), functor, callback, | |
136 callback_host)); | |
137 DoInvoke(posted_from, thread, std::move(closure), id); | |
138 } | |
139 | |
140 // Synchronously execute on |thread| all outstanding calls we own | 103 // Synchronously execute on |thread| all outstanding calls we own |
141 // that are pending on |thread|, and wait for calls to complete | 104 // that are pending on |thread|, and wait for calls to complete |
142 // before returning. Optionally filter by message id. | 105 // before returning. Optionally filter by message id. |
143 // The destructor will not wait for outstanding calls, so if that | 106 // The destructor will not wait for outstanding calls, so if that |
144 // behavior is desired, call Flush() before destroying this object. | 107 // behavior is desired, call Flush() before destroying this object. |
145 void Flush(Thread* thread, uint32_t id = MQID_ANY); | 108 void Flush(Thread* thread, uint32_t id = MQID_ANY); |
146 | 109 |
147 private: | 110 private: |
148 void OnMessage(Message* msg) override; | 111 void OnMessage(Message* msg) override; |
149 void DoInvoke(const Location& posted_from, | 112 void DoInvoke(const Location& posted_from, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 void ThreadDestroyed(); | 212 void ThreadDestroyed(); |
250 | 213 |
251 CriticalSection crit_; | 214 CriticalSection crit_; |
252 Thread* thread_ GUARDED_BY(crit_); | 215 Thread* thread_ GUARDED_BY(crit_); |
253 AsyncInvoker invoker_ GUARDED_BY(crit_); | 216 AsyncInvoker invoker_ GUARDED_BY(crit_); |
254 }; | 217 }; |
255 | 218 |
256 } // namespace rtc | 219 } // namespace rtc |
257 | 220 |
258 #endif // WEBRTC_BASE_ASYNCINVOKER_H_ | 221 #endif // WEBRTC_BASE_ASYNCINVOKER_H_ |
OLD | NEW |