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

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

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