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

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

Issue 2019423006: Adding more detail to MessageQueue::Dispatch logging. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing one more place where RTC_FROM_HERE wasn't used. Created 4 years, 6 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/base/location.cc ('k') | webrtc/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
11 #ifndef WEBRTC_BASE_MESSAGEQUEUE_H_ 11 #ifndef WEBRTC_BASE_MESSAGEQUEUE_H_
12 #define WEBRTC_BASE_MESSAGEQUEUE_H_ 12 #define WEBRTC_BASE_MESSAGEQUEUE_H_
13 13
14 #include <string.h> 14 #include <string.h>
15 15
16 #include <algorithm> 16 #include <algorithm>
17 #include <list> 17 #include <list>
18 #include <memory> 18 #include <memory>
19 #include <queue> 19 #include <queue>
20 #include <vector> 20 #include <vector>
21 21
22 #include "webrtc/base/basictypes.h" 22 #include "webrtc/base/basictypes.h"
23 #include "webrtc/base/constructormagic.h" 23 #include "webrtc/base/constructormagic.h"
24 #include "webrtc/base/criticalsection.h" 24 #include "webrtc/base/criticalsection.h"
25 #include "webrtc/base/location.h"
25 #include "webrtc/base/messagehandler.h" 26 #include "webrtc/base/messagehandler.h"
26 #include "webrtc/base/scoped_ref_ptr.h" 27 #include "webrtc/base/scoped_ref_ptr.h"
27 #include "webrtc/base/sharedexclusivelock.h" 28 #include "webrtc/base/sharedexclusivelock.h"
28 #include "webrtc/base/sigslot.h" 29 #include "webrtc/base/sigslot.h"
29 #include "webrtc/base/socketserver.h" 30 #include "webrtc/base/socketserver.h"
30 #include "webrtc/base/timeutils.h" 31 #include "webrtc/base/timeutils.h"
31 #include "webrtc/base/thread_annotations.h" 32 #include "webrtc/base/thread_annotations.h"
32 33
33 namespace rtc { 34 namespace rtc {
34 35
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 private: 132 private:
132 T* data_; 133 T* data_;
133 }; 134 };
134 135
135 const uint32_t MQID_ANY = static_cast<uint32_t>(-1); 136 const uint32_t MQID_ANY = static_cast<uint32_t>(-1);
136 const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2); 137 const uint32_t MQID_DISPOSE = static_cast<uint32_t>(-2);
137 138
138 // No destructor 139 // No destructor
139 140
140 struct Message { 141 struct Message {
141 Message() { 142 Message()
142 memset(this, 0, sizeof(*this)); 143 : phandler(nullptr), message_id(0), pdata(nullptr), ts_sensitive(0) {}
143 }
144 inline bool Match(MessageHandler* handler, uint32_t id) const { 144 inline bool Match(MessageHandler* handler, uint32_t id) const {
145 return (handler == NULL || handler == phandler) 145 return (handler == NULL || handler == phandler)
146 && (id == MQID_ANY || id == message_id); 146 && (id == MQID_ANY || id == message_id);
147 } 147 }
148 Location posted_from;
148 MessageHandler *phandler; 149 MessageHandler *phandler;
149 uint32_t message_id; 150 uint32_t message_id;
150 MessageData *pdata; 151 MessageData *pdata;
151 int64_t ts_sensitive; 152 int64_t ts_sensitive;
152 }; 153 };
153 154
154 typedef std::list<Message> MessageList; 155 typedef std::list<Message> MessageList;
155 156
156 // DelayedMessage goes into a priority queue, sorted by trigger time. Messages 157 // DelayedMessage goes into a priority queue, sorted by trigger time. Messages
157 // with the same trigger time are processed in num_ (FIFO) order. 158 // with the same trigger time are processed in num_ (FIFO) order.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 virtual bool IsQuitting(); 207 virtual bool IsQuitting();
207 virtual void Restart(); 208 virtual void Restart();
208 209
209 // Get() will process I/O until: 210 // Get() will process I/O until:
210 // 1) A message is available (returns true) 211 // 1) A message is available (returns true)
211 // 2) cmsWait seconds have elapsed (returns false) 212 // 2) cmsWait seconds have elapsed (returns false)
212 // 3) Stop() is called (returns false) 213 // 3) Stop() is called (returns false)
213 virtual bool Get(Message *pmsg, int cmsWait = kForever, 214 virtual bool Get(Message *pmsg, int cmsWait = kForever,
214 bool process_io = true); 215 bool process_io = true);
215 virtual bool Peek(Message *pmsg, int cmsWait = 0); 216 virtual bool Peek(Message *pmsg, int cmsWait = 0);
216 virtual void Post(MessageHandler* phandler, 217 virtual void Post(const Location& posted_from,
218 MessageHandler* phandler,
217 uint32_t id = 0, 219 uint32_t id = 0,
218 MessageData* pdata = NULL, 220 MessageData* pdata = NULL,
219 bool time_sensitive = false); 221 bool time_sensitive = false);
220 virtual void PostDelayed(int cmsDelay, 222 virtual void PostDelayed(const Location& posted_from,
223 int cmsDelay,
221 MessageHandler* phandler, 224 MessageHandler* phandler,
222 uint32_t id = 0, 225 uint32_t id = 0,
223 MessageData* pdata = NULL); 226 MessageData* pdata = NULL);
224 virtual void PostAt(int64_t tstamp, 227 virtual void PostAt(const Location& posted_from,
228 int64_t tstamp,
225 MessageHandler* phandler, 229 MessageHandler* phandler,
226 uint32_t id = 0, 230 uint32_t id = 0,
227 MessageData* pdata = NULL); 231 MessageData* pdata = NULL);
228 // TODO(honghaiz): Remove this when all the dependencies are removed. 232 // TODO(honghaiz): Remove this when all the dependencies are removed.
229 virtual void PostAt(uint32_t tstamp, 233 virtual void PostAt(const Location& posted_from,
234 uint32_t tstamp,
230 MessageHandler* phandler, 235 MessageHandler* phandler,
231 uint32_t id = 0, 236 uint32_t id = 0,
232 MessageData* pdata = NULL); 237 MessageData* pdata = NULL);
233 virtual void Clear(MessageHandler* phandler, 238 virtual void Clear(MessageHandler* phandler,
234 uint32_t id = MQID_ANY, 239 uint32_t id = MQID_ANY,
235 MessageList* removed = NULL); 240 MessageList* removed = NULL);
236 virtual void Dispatch(Message *pmsg); 241 virtual void Dispatch(Message *pmsg);
237 virtual void ReceiveSends(); 242 virtual void ReceiveSends();
238 243
239 // Amount of time until the next message can be retrieved 244 // Amount of time until the next message can be retrieved
240 virtual int GetDelay(); 245 virtual int GetDelay();
241 246
242 bool empty() const { return size() == 0u; } 247 bool empty() const { return size() == 0u; }
243 size_t size() const { 248 size_t size() const {
244 CritScope cs(&crit_); // msgq_.size() is not thread safe. 249 CritScope cs(&crit_); // msgq_.size() is not thread safe.
245 return msgq_.size() + dmsgq_.size() + (fPeekKeep_ ? 1u : 0u); 250 return msgq_.size() + dmsgq_.size() + (fPeekKeep_ ? 1u : 0u);
246 } 251 }
247 252
248 // Internally posts a message which causes the doomed object to be deleted 253 // Internally posts a message which causes the doomed object to be deleted
249 template<class T> void Dispose(T* doomed) { 254 template<class T> void Dispose(T* doomed) {
250 if (doomed) { 255 if (doomed) {
251 Post(NULL, MQID_DISPOSE, new DisposeData<T>(doomed)); 256 Post(RTC_FROM_HERE, NULL, MQID_DISPOSE, new DisposeData<T>(doomed));
252 } 257 }
253 } 258 }
254 259
255 // When this signal is sent out, any references to this queue should 260 // When this signal is sent out, any references to this queue should
256 // no longer be used. 261 // no longer be used.
257 sigslot::signal0<> SignalQueueDestroyed; 262 sigslot::signal0<> SignalQueueDestroyed;
258 263
259 protected: 264 protected:
260 class PriorityQueue : public std::priority_queue<DelayedMessage> { 265 class PriorityQueue : public std::priority_queue<DelayedMessage> {
261 public: 266 public:
262 container_type& container() { return c; } 267 container_type& container() { return c; }
263 void reheap() { make_heap(c.begin(), c.end(), comp); } 268 void reheap() { make_heap(c.begin(), c.end(), comp); }
264 }; 269 };
265 270
266 void DoDelayPost(int64_t cmsDelay, 271 void DoDelayPost(const Location& posted_from,
272 int64_t cmsDelay,
267 int64_t tstamp, 273 int64_t tstamp,
268 MessageHandler* phandler, 274 MessageHandler* phandler,
269 uint32_t id, 275 uint32_t id,
270 MessageData* pdata); 276 MessageData* pdata);
271 277
272 // Perform initialization, subclasses must call this from their constructor 278 // Perform initialization, subclasses must call this from their constructor
273 // if false was passed as init_queue to the MessageQueue constructor. 279 // if false was passed as init_queue to the MessageQueue constructor.
274 void DoInit(); 280 void DoInit();
275 281
276 // Perform cleanup, subclasses that override Clear must call this from the 282 // Perform cleanup, subclasses that override Clear must call this from the
(...skipping 18 matching lines...) Expand all
295 // Used if SocketServer ownership lies with |this|. 301 // Used if SocketServer ownership lies with |this|.
296 std::unique_ptr<SocketServer> own_ss_; 302 std::unique_ptr<SocketServer> own_ss_;
297 SharedExclusiveLock ss_lock_; 303 SharedExclusiveLock ss_lock_;
298 304
299 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); 305 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue);
300 }; 306 };
301 307
302 } // namespace rtc 308 } // namespace rtc
303 309
304 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ 310 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_
OLDNEW
« no previous file with comments | « webrtc/base/location.cc ('k') | webrtc/base/messagequeue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698