Chromium Code Reviews| 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; | |
|
tommi
2017/06/27 12:01:14
virtual void Call() = 0;
Btw, this seems to now b
kwiberg-webrtc
2017/06/27 13:14:56
sgtm---the new Post() call could take a unique_ptr
nisse-webrtc
2017/06/28 11:47:54
Done.
tommi
2017/06/28 13:17:33
yes, I think so
nisse-webrtc
2017/06/29 10:40:31
I've renamed Call to Run, and Callable to Runnable
nisse-webrtc
2017/06/29 10:40:32
Sounds like it could work, I'll give it a try, but
| |
| 153 }; | |
| 154 | |
| 155 template <class FunctorT> | |
| 156 class FunctorData : public CallableData { | |
| 157 public: | |
| 158 explicit FunctorData(FunctorT functor) : functor_(std::move(functor)) {} | |
| 159 void Call(void) override { functor_(); } | |
|
tommi
2017/06/27 12:01:14
same here (no 'void' when there aren't any argumen
| |
| 160 | |
| 161 private: | |
| 162 FunctorT functor_; | |
| 163 }; | |
| 164 | |
| 150 const uint32_t MQID_ANY = static_cast<uint32_t>(-1); | 165 const uint32_t MQID_ANY = static_cast<uint32_t>(-1); |
| 151 const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2); | 166 const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2); |
| 152 | 167 |
| 153 // No destructor | 168 // No destructor |
| 154 | 169 |
| 155 struct Message { | 170 struct Message { |
| 156 Message() | 171 Message() |
| 157 : phandler(nullptr), message_id(0), pdata(nullptr), ts_sensitive(0) {} | 172 : phandler(nullptr), message_id(0), pdata(nullptr), ts_sensitive(0) {} |
| 158 inline bool Match(MessageHandler* handler, uint32_t id) const { | 173 inline bool Match(MessageHandler* handler, uint32_t id) const { |
| 159 return (handler == nullptr || handler == phandler) && | 174 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) | 244 // 2) cmsWait seconds have elapsed (returns false) |
| 230 // 3) Stop() is called (returns false) | 245 // 3) Stop() is called (returns false) |
| 231 virtual bool Get(Message *pmsg, int cmsWait = kForever, | 246 virtual bool Get(Message *pmsg, int cmsWait = kForever, |
| 232 bool process_io = true); | 247 bool process_io = true); |
| 233 virtual bool Peek(Message *pmsg, int cmsWait = 0); | 248 virtual bool Peek(Message *pmsg, int cmsWait = 0); |
| 234 virtual void Post(const Location& posted_from, | 249 virtual void Post(const Location& posted_from, |
| 235 MessageHandler* phandler, | 250 MessageHandler* phandler, |
| 236 uint32_t id = 0, | 251 uint32_t id = 0, |
| 237 MessageData* pdata = nullptr, | 252 MessageData* pdata = nullptr, |
| 238 bool time_sensitive = false); | 253 bool time_sensitive = false); |
| 254 | |
| 255 // Additional type check, or else it collides with calls to the | |
| 256 // above Post method with the optional arguments omitted. | |
| 257 template <class FunctorT, | |
| 258 typename std::enable_if<!std::is_pointer<FunctorT>::value>::type* = | |
| 259 nullptr> | |
| 260 void Post(const Location& posted_from, FunctorT functor) { | |
| 261 PostFunctorInternal(posted_from, | |
| 262 new FunctorData<FunctorT>(std::move(functor))); | |
| 263 } | |
| 264 | |
| 239 virtual void PostDelayed(const Location& posted_from, | 265 virtual void PostDelayed(const Location& posted_from, |
| 240 int cmsDelay, | 266 int cmsDelay, |
| 241 MessageHandler* phandler, | 267 MessageHandler* phandler, |
| 242 uint32_t id = 0, | 268 uint32_t id = 0, |
| 243 MessageData* pdata = nullptr); | 269 MessageData* pdata = nullptr); |
| 244 virtual void PostAt(const Location& posted_from, | 270 virtual void PostAt(const Location& posted_from, |
| 245 int64_t tstamp, | 271 int64_t tstamp, |
| 246 MessageHandler* phandler, | 272 MessageHandler* phandler, |
| 247 uint32_t id = 0, | 273 uint32_t id = 0, |
| 248 MessageData* pdata = nullptr); | 274 MessageData* pdata = nullptr); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 bool fPeekKeep_; | 331 bool fPeekKeep_; |
| 306 Message msgPeek_; | 332 Message msgPeek_; |
| 307 MessageList msgq_ GUARDED_BY(crit_); | 333 MessageList msgq_ GUARDED_BY(crit_); |
| 308 PriorityQueue dmsgq_ GUARDED_BY(crit_); | 334 PriorityQueue dmsgq_ GUARDED_BY(crit_); |
| 309 uint32_t dmsgq_next_num_ GUARDED_BY(crit_); | 335 uint32_t dmsgq_next_num_ GUARDED_BY(crit_); |
| 310 CriticalSection crit_; | 336 CriticalSection crit_; |
| 311 bool fInitialized_; | 337 bool fInitialized_; |
| 312 bool fDestroyed_; | 338 bool fDestroyed_; |
| 313 | 339 |
| 314 private: | 340 private: |
| 341 void PostFunctorInternal(const Location& posted_from, | |
| 342 CallableData* message_data); | |
| 343 | |
| 315 volatile int stop_; | 344 volatile int stop_; |
| 316 | 345 |
| 317 // The SocketServer might not be owned by MessageQueue. | 346 // The SocketServer might not be owned by MessageQueue. |
| 318 SocketServer* const ss_; | 347 SocketServer* const ss_; |
| 319 // Used if SocketServer ownership lies with |this|. | 348 // Used if SocketServer ownership lies with |this|. |
| 320 std::unique_ptr<SocketServer> own_ss_; | 349 std::unique_ptr<SocketServer> own_ss_; |
| 321 | 350 |
| 322 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); | 351 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); |
| 323 }; | 352 }; |
| 324 | 353 |
| 325 } // namespace rtc | 354 } // namespace rtc |
| 326 | 355 |
| 327 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ | 356 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ |
| OLD | NEW |