Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: webrtc/rtc_base/messagequeue.h

Issue 2915253002: Delete SignalThread class. (Closed)
Patch Set: Added TODO comment on posting of QueuedTask. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/rtc_base/BUILD.gn ('k') | webrtc/rtc_base/messagequeue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 RunnableData : public MessageData {
tommi 2017/06/29 12:27:52 can you add a TODO here to move over to using Queu
nisse-webrtc 2017/06/29 12:38:38 Done.
151 public:
152 virtual void Run() = 0;
153 };
154
155 template <class FunctorT>
156 class FunctorData : public RunnableData {
157 public:
158 explicit FunctorData(FunctorT functor) : functor_(std::move(functor)) {}
159 void Run() override { functor_(); }
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
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 // TODO(nisse): Replace with a method for posting a
256 // std::unique_ptr<QueuedTask>, to ease gradual conversion to using TaskQueue.
257 template <class FunctorT,
258 // Additional type check, or else it collides with calls to the
259 // above Post method with the optional arguments omitted.
260 typename std::enable_if<!std::is_pointer<FunctorT>::value>::type* =
261 nullptr>
262 void Post(const Location& posted_from, FunctorT functor) {
263 PostFunctorInternal(posted_from,
264 new FunctorData<FunctorT>(std::move(functor)));
265 }
266
239 virtual void PostDelayed(const Location& posted_from, 267 virtual void PostDelayed(const Location& posted_from,
240 int cmsDelay, 268 int cmsDelay,
241 MessageHandler* phandler, 269 MessageHandler* phandler,
242 uint32_t id = 0, 270 uint32_t id = 0,
243 MessageData* pdata = nullptr); 271 MessageData* pdata = nullptr);
244 virtual void PostAt(const Location& posted_from, 272 virtual void PostAt(const Location& posted_from,
245 int64_t tstamp, 273 int64_t tstamp,
246 MessageHandler* phandler, 274 MessageHandler* phandler,
247 uint32_t id = 0, 275 uint32_t id = 0,
248 MessageData* pdata = nullptr); 276 MessageData* pdata = nullptr);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 bool fPeekKeep_; 333 bool fPeekKeep_;
306 Message msgPeek_; 334 Message msgPeek_;
307 MessageList msgq_ GUARDED_BY(crit_); 335 MessageList msgq_ GUARDED_BY(crit_);
308 PriorityQueue dmsgq_ GUARDED_BY(crit_); 336 PriorityQueue dmsgq_ GUARDED_BY(crit_);
309 uint32_t dmsgq_next_num_ GUARDED_BY(crit_); 337 uint32_t dmsgq_next_num_ GUARDED_BY(crit_);
310 CriticalSection crit_; 338 CriticalSection crit_;
311 bool fInitialized_; 339 bool fInitialized_;
312 bool fDestroyed_; 340 bool fDestroyed_;
313 341
314 private: 342 private:
343 void PostFunctorInternal(const Location& posted_from,
344 RunnableData* message_data);
345
315 volatile int stop_; 346 volatile int stop_;
316 347
317 // The SocketServer might not be owned by MessageQueue. 348 // The SocketServer might not be owned by MessageQueue.
318 SocketServer* const ss_; 349 SocketServer* const ss_;
319 // Used if SocketServer ownership lies with |this|. 350 // Used if SocketServer ownership lies with |this|.
320 std::unique_ptr<SocketServer> own_ss_; 351 std::unique_ptr<SocketServer> own_ss_;
321 352
322 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); 353 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue);
323 }; 354 };
324 355
325 } // namespace rtc 356 } // namespace rtc
326 357
327 #endif // WEBRTC_RTC_BASE_MESSAGEQUEUE_H_ 358 #endif // WEBRTC_RTC_BASE_MESSAGEQUEUE_H_
OLDNEW
« no previous file with comments | « webrtc/rtc_base/BUILD.gn ('k') | webrtc/rtc_base/messagequeue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698