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

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

Issue 2915253002: Delete SignalThread class. (Closed)
Patch Set: Another TODO on moving to 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 // TODO(nisse): Replace RunnableData and FunctorData by a subclass of Message
151 // owning a QueuedTask.
152 class RunnableData : public MessageData {
153 public:
154 virtual void Run() = 0;
155 };
156
157 template <class FunctorT>
158 class FunctorData : public RunnableData {
159 public:
160 explicit FunctorData(FunctorT functor) : functor_(std::move(functor)) {}
161 void Run() override { functor_(); }
162
163 private:
164 FunctorT functor_;
165 };
166
150 const uint32_t MQID_ANY = static_cast<uint32_t>(-1); 167 const uint32_t MQID_ANY = static_cast<uint32_t>(-1);
151 const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2); 168 const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2);
152 169
153 // No destructor 170 // No destructor
154 171
155 struct Message { 172 struct Message {
156 Message() 173 Message()
157 : phandler(nullptr), message_id(0), pdata(nullptr), ts_sensitive(0) {} 174 : phandler(nullptr), message_id(0), pdata(nullptr), ts_sensitive(0) {}
158 inline bool Match(MessageHandler* handler, uint32_t id) const { 175 inline bool Match(MessageHandler* handler, uint32_t id) const {
159 return (handler == nullptr || handler == phandler) && 176 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) 246 // 2) cmsWait seconds have elapsed (returns false)
230 // 3) Stop() is called (returns false) 247 // 3) Stop() is called (returns false)
231 virtual bool Get(Message *pmsg, int cmsWait = kForever, 248 virtual bool Get(Message *pmsg, int cmsWait = kForever,
232 bool process_io = true); 249 bool process_io = true);
233 virtual bool Peek(Message *pmsg, int cmsWait = 0); 250 virtual bool Peek(Message *pmsg, int cmsWait = 0);
234 virtual void Post(const Location& posted_from, 251 virtual void Post(const Location& posted_from,
235 MessageHandler* phandler, 252 MessageHandler* phandler,
236 uint32_t id = 0, 253 uint32_t id = 0,
237 MessageData* pdata = nullptr, 254 MessageData* pdata = nullptr,
238 bool time_sensitive = false); 255 bool time_sensitive = false);
256
257 // TODO(nisse): Replace with a method for posting a
258 // std::unique_ptr<QueuedTask>, to ease gradual conversion to using TaskQueue.
259 template <class FunctorT,
260 // Additional type check, or else it collides with calls to the
261 // above Post method with the optional arguments omitted.
262 typename std::enable_if<!std::is_pointer<FunctorT>::value>::type* =
263 nullptr>
264 void Post(const Location& posted_from, FunctorT functor) {
265 PostFunctorInternal(posted_from,
266 new FunctorData<FunctorT>(std::move(functor)));
267 }
268
239 virtual void PostDelayed(const Location& posted_from, 269 virtual void PostDelayed(const Location& posted_from,
240 int cmsDelay, 270 int cmsDelay,
241 MessageHandler* phandler, 271 MessageHandler* phandler,
242 uint32_t id = 0, 272 uint32_t id = 0,
243 MessageData* pdata = nullptr); 273 MessageData* pdata = nullptr);
244 virtual void PostAt(const Location& posted_from, 274 virtual void PostAt(const Location& posted_from,
245 int64_t tstamp, 275 int64_t tstamp,
246 MessageHandler* phandler, 276 MessageHandler* phandler,
247 uint32_t id = 0, 277 uint32_t id = 0,
248 MessageData* pdata = nullptr); 278 MessageData* pdata = nullptr);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 bool fPeekKeep_; 335 bool fPeekKeep_;
306 Message msgPeek_; 336 Message msgPeek_;
307 MessageList msgq_ GUARDED_BY(crit_); 337 MessageList msgq_ GUARDED_BY(crit_);
308 PriorityQueue dmsgq_ GUARDED_BY(crit_); 338 PriorityQueue dmsgq_ GUARDED_BY(crit_);
309 uint32_t dmsgq_next_num_ GUARDED_BY(crit_); 339 uint32_t dmsgq_next_num_ GUARDED_BY(crit_);
310 CriticalSection crit_; 340 CriticalSection crit_;
311 bool fInitialized_; 341 bool fInitialized_;
312 bool fDestroyed_; 342 bool fDestroyed_;
313 343
314 private: 344 private:
345 void PostFunctorInternal(const Location& posted_from,
346 RunnableData* message_data);
347
315 volatile int stop_; 348 volatile int stop_;
316 349
317 // The SocketServer might not be owned by MessageQueue. 350 // The SocketServer might not be owned by MessageQueue.
318 SocketServer* const ss_; 351 SocketServer* const ss_;
319 // Used if SocketServer ownership lies with |this|. 352 // Used if SocketServer ownership lies with |this|.
320 std::unique_ptr<SocketServer> own_ss_; 353 std::unique_ptr<SocketServer> own_ss_;
321 354
322 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); 355 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue);
323 }; 356 };
324 357
325 } // namespace rtc 358 } // namespace rtc
326 359
327 #endif // WEBRTC_RTC_BASE_MESSAGEQUEUE_H_ 360 #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