OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 | 140 |
141 template<class T> | 141 template<class T> |
142 class DisposeData : public MessageData { | 142 class DisposeData : public MessageData { |
143 public: | 143 public: |
144 explicit DisposeData(T* data) : data_(data) { } | 144 explicit DisposeData(T* data) : data_(data) { } |
145 virtual ~DisposeData() { delete data_; } | 145 virtual ~DisposeData() { delete data_; } |
146 private: | 146 private: |
147 T* data_; | 147 T* data_; |
148 }; | 148 }; |
149 | 149 |
150 class CallableData : public MessageData { | |
151 public: | |
152 virtual void call(void) = 0; | |
kwiberg-webrtc
2017/06/26 13:07:48
"Call"
nisse-webrtc
2017/06/27 08:27:17
Done.
| |
153 }; | |
154 | |
155 template <class FunctorT> | |
156 class FunctorData : public CallableData { | |
157 public: | |
158 explicit FunctorData(FunctorT functor) | |
159 : functor_(std::move(functor)) {} | |
160 void call(void) override { functor_(); } | |
161 | |
162 private: | |
163 FunctorT functor_; | |
164 }; | |
165 | |
150 const uint32_t MQID_ANY = static_cast<uint32_t>(-1); | 166 const uint32_t MQID_ANY = static_cast<uint32_t>(-1); |
151 const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2); | 167 const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2); |
152 | 168 |
153 // No destructor | 169 // No destructor |
154 | 170 |
155 struct Message { | 171 struct Message { |
156 Message() | 172 Message() |
157 : phandler(nullptr), message_id(0), pdata(nullptr), ts_sensitive(0) {} | 173 : phandler(nullptr), message_id(0), pdata(nullptr), ts_sensitive(0) {} |
158 inline bool Match(MessageHandler* handler, uint32_t id) const { | 174 inline bool Match(MessageHandler* handler, uint32_t id) const { |
159 return (handler == nullptr || handler == phandler) && | 175 return (handler == nullptr || handler == phandler) && |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 // 2) cmsWait seconds have elapsed (returns false) | 245 // 2) cmsWait seconds have elapsed (returns false) |
230 // 3) Stop() is called (returns false) | 246 // 3) Stop() is called (returns false) |
231 virtual bool Get(Message *pmsg, int cmsWait = kForever, | 247 virtual bool Get(Message *pmsg, int cmsWait = kForever, |
232 bool process_io = true); | 248 bool process_io = true); |
233 virtual bool Peek(Message *pmsg, int cmsWait = 0); | 249 virtual bool Peek(Message *pmsg, int cmsWait = 0); |
234 virtual void Post(const Location& posted_from, | 250 virtual void Post(const Location& posted_from, |
235 MessageHandler* phandler, | 251 MessageHandler* phandler, |
236 uint32_t id = 0, | 252 uint32_t id = 0, |
237 MessageData* pdata = nullptr, | 253 MessageData* pdata = nullptr, |
238 bool time_sensitive = false); | 254 bool time_sensitive = false); |
255 // TODO(nisse): Can this be renamed to just Post? Needs some | |
256 // additional type check, or else it collides with calls to the | |
257 // above Post method with optional arguments omitted. | |
kwiberg-webrtc
2017/06/26 13:07:48
Should be simple to do by e.g. using enable_if to
nisse-webrtc
2017/06/27 08:27:17
Done.
| |
258 template <class FunctorT> | |
259 void PostFunctor(const Location& posted_from, FunctorT functor) { | |
260 PostFunctorInternal(posted_from, | |
261 new FunctorData<FunctorT>(std::move(functor))); | |
262 } | |
263 | |
239 virtual void PostDelayed(const Location& posted_from, | 264 virtual void PostDelayed(const Location& posted_from, |
240 int cmsDelay, | 265 int cmsDelay, |
241 MessageHandler* phandler, | 266 MessageHandler* phandler, |
242 uint32_t id = 0, | 267 uint32_t id = 0, |
243 MessageData* pdata = nullptr); | 268 MessageData* pdata = nullptr); |
244 virtual void PostAt(const Location& posted_from, | 269 virtual void PostAt(const Location& posted_from, |
245 int64_t tstamp, | 270 int64_t tstamp, |
246 MessageHandler* phandler, | 271 MessageHandler* phandler, |
247 uint32_t id = 0, | 272 uint32_t id = 0, |
248 MessageData* pdata = nullptr); | 273 MessageData* pdata = nullptr); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 bool fPeekKeep_; | 330 bool fPeekKeep_; |
306 Message msgPeek_; | 331 Message msgPeek_; |
307 MessageList msgq_ GUARDED_BY(crit_); | 332 MessageList msgq_ GUARDED_BY(crit_); |
308 PriorityQueue dmsgq_ GUARDED_BY(crit_); | 333 PriorityQueue dmsgq_ GUARDED_BY(crit_); |
309 uint32_t dmsgq_next_num_ GUARDED_BY(crit_); | 334 uint32_t dmsgq_next_num_ GUARDED_BY(crit_); |
310 CriticalSection crit_; | 335 CriticalSection crit_; |
311 bool fInitialized_; | 336 bool fInitialized_; |
312 bool fDestroyed_; | 337 bool fDestroyed_; |
313 | 338 |
314 private: | 339 private: |
340 void PostFunctorInternal(const Location& posted_from, | |
341 CallableData* message_data); | |
342 | |
315 volatile int stop_; | 343 volatile int stop_; |
316 | 344 |
317 // The SocketServer might not be owned by MessageQueue. | 345 // The SocketServer might not be owned by MessageQueue. |
318 SocketServer* const ss_; | 346 SocketServer* const ss_; |
319 // Used if SocketServer ownership lies with |this|. | 347 // Used if SocketServer ownership lies with |this|. |
320 std::unique_ptr<SocketServer> own_ss_; | 348 std::unique_ptr<SocketServer> own_ss_; |
321 | 349 |
322 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); | 350 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); |
323 }; | 351 }; |
324 | 352 |
325 } // namespace rtc | 353 } // namespace rtc |
326 | 354 |
327 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ | 355 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ |
OLD | NEW |