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

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

Issue 1835053002: Change default timestamp to 64 bits in all webrtc directories. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 8 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
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 #if defined(WEBRTC_POSIX) 11 #if defined(WEBRTC_POSIX)
12 #include <sys/time.h> 12 #include <sys/time.h>
13 #endif 13 #endif
14 14
15 #include <algorithm> 15 #include <algorithm>
16 16
17 #include "webrtc/base/common.h" 17 #include "webrtc/base/common.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 #include "webrtc/base/messagequeue.h" 19 #include "webrtc/base/messagequeue.h"
20 #if defined(__native_client__) 20 #if defined(__native_client__)
21 #include "webrtc/base/nullsocketserver.h" 21 #include "webrtc/base/nullsocketserver.h"
22 typedef rtc::NullSocketServer DefaultSocketServer; 22 typedef rtc::NullSocketServer DefaultSocketServer;
23 #else 23 #else
24 #include "webrtc/base/physicalsocketserver.h" 24 #include "webrtc/base/physicalsocketserver.h"
25 typedef rtc::PhysicalSocketServer DefaultSocketServer; 25 typedef rtc::PhysicalSocketServer DefaultSocketServer;
26 #endif 26 #endif
27 27
28 namespace rtc { 28 namespace rtc {
29 29
30 const uint32_t kMaxMsgLatency = 150; // 150 ms 30 const int kMaxMsgLatency = 150; // 150 ms
pthatcher1 2016/04/11 20:56:59 Why not uint64_t?
honghaiz3 2016/04/18 23:39:03 According to style guide, we should not use uintXX
31 31
32 //------------------------------------------------------------------ 32 //------------------------------------------------------------------
33 // MessageQueueManager 33 // MessageQueueManager
34 34
35 MessageQueueManager* MessageQueueManager::instance_ = NULL; 35 MessageQueueManager* MessageQueueManager::instance_ = NULL;
36 36
37 MessageQueueManager* MessageQueueManager::Instance() { 37 MessageQueueManager* MessageQueueManager::Instance() {
38 // Note: This is not thread safe, but it is first called before threads are 38 // Note: This is not thread safe, but it is first called before threads are
39 // spawned. 39 // spawned.
40 if (!instance_) 40 if (!instance_)
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if (fPeekKeep_) { 219 if (fPeekKeep_) {
220 *pmsg = msgPeek_; 220 *pmsg = msgPeek_;
221 fPeekKeep_ = false; 221 fPeekKeep_ = false;
222 return true; 222 return true;
223 } 223 }
224 224
225 // Get w/wait + timer scan / dispatch + socket / event multiplexer dispatch 225 // Get w/wait + timer scan / dispatch + socket / event multiplexer dispatch
226 226
227 int cmsTotal = cmsWait; 227 int cmsTotal = cmsWait;
228 int cmsElapsed = 0; 228 int cmsElapsed = 0;
229 uint32_t msStart = Time(); 229 int64_t msStart = Time();
230 uint32_t msCurrent = msStart; 230 int64_t msCurrent = msStart;
231 while (true) { 231 while (true) {
232 // Check for sent messages 232 // Check for sent messages
233 ReceiveSends(); 233 ReceiveSends();
234 234
235 // Check for posted events 235 // Check for posted events
236 int cmsDelayNext = kForever; 236 int cmsDelayNext = kForever;
237 bool first_pass = true; 237 bool first_pass = true;
238 while (true) { 238 while (true) {
239 // All queue operations need to be locked, but nothing else in this loop 239 // All queue operations need to be locked, but nothing else in this loop
240 // (specifically handling disposed message) can happen inside the crit. 240 // (specifically handling disposed message) can happen inside the crit.
241 // Otherwise, disposed MessageHandlers will cause deadlocks. 241 // Otherwise, disposed MessageHandlers will cause deadlocks.
242 { 242 {
243 CritScope cs(&crit_); 243 CritScope cs(&crit_);
244 // On the first pass, check for delayed messages that have been 244 // On the first pass, check for delayed messages that have been
245 // triggered and calculate the next trigger time. 245 // triggered and calculate the next trigger time.
246 if (first_pass) { 246 if (first_pass) {
247 first_pass = false; 247 first_pass = false;
248 while (!dmsgq_.empty()) { 248 while (!dmsgq_.empty()) {
249 if (TimeIsLater(msCurrent, dmsgq_.top().msTrigger_)) { 249 if (msCurrent < dmsgq_.top().msTrigger_) {
250 cmsDelayNext = TimeDiff(dmsgq_.top().msTrigger_, msCurrent); 250 cmsDelayNext = TimeDiff(dmsgq_.top().msTrigger_, msCurrent);
251 break; 251 break;
252 } 252 }
253 msgq_.push_back(dmsgq_.top().msg_); 253 msgq_.push_back(dmsgq_.top().msg_);
254 dmsgq_.pop(); 254 dmsgq_.pop();
255 } 255 }
256 } 256 }
257 // Pull a message off the message queue, if available. 257 // Pull a message off the message queue, if available.
258 if (msgq_.empty()) { 258 if (msgq_.empty()) {
259 break; 259 break;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 WakeUpSocketServer(); 342 WakeUpSocketServer();
343 } 343 }
344 344
345 void MessageQueue::PostDelayed(int cmsDelay, 345 void MessageQueue::PostDelayed(int cmsDelay,
346 MessageHandler* phandler, 346 MessageHandler* phandler,
347 uint32_t id, 347 uint32_t id,
348 MessageData* pdata) { 348 MessageData* pdata) {
349 return DoDelayPost(cmsDelay, TimeAfter(cmsDelay), phandler, id, pdata); 349 return DoDelayPost(cmsDelay, TimeAfter(cmsDelay), phandler, id, pdata);
350 } 350 }
351 351
352 void MessageQueue::PostAt(uint32_t tstamp, 352 void MessageQueue::PostAt(int64_t tstamp,
353 MessageHandler* phandler, 353 MessageHandler* phandler,
354 uint32_t id, 354 uint32_t id,
355 MessageData* pdata) { 355 MessageData* pdata) {
356 return DoDelayPost(TimeUntil(tstamp), tstamp, phandler, id, pdata); 356 return DoDelayPost(TimeUntil(tstamp), tstamp, phandler, id, pdata);
357 } 357 }
358 358
359 void MessageQueue::DoDelayPost(int cmsDelay, 359 void MessageQueue::DoDelayPost(int cmsDelay,
360 uint32_t tstamp, 360 int64_t tstamp,
361 MessageHandler* phandler, 361 MessageHandler* phandler,
362 uint32_t id, 362 uint32_t id,
363 MessageData* pdata) { 363 MessageData* pdata) {
364 if (fStop_) 364 if (fStop_)
365 return; 365 return;
366 366
367 // Keep thread safe 367 // Keep thread safe
368 // Add to the priority queue. Gets sorted soonest first. 368 // Add to the priority queue. Gets sorted soonest first.
369 // Signal for the multiplexer to return. 369 // Signal for the multiplexer to return.
370 370
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 448 }
449 dmsgq_.container().erase(new_end, dmsgq_.container().end()); 449 dmsgq_.container().erase(new_end, dmsgq_.container().end());
450 dmsgq_.reheap(); 450 dmsgq_.reheap();
451 } 451 }
452 452
453 void MessageQueue::Dispatch(Message *pmsg) { 453 void MessageQueue::Dispatch(Message *pmsg) {
454 pmsg->phandler->OnMessage(pmsg); 454 pmsg->phandler->OnMessage(pmsg);
455 } 455 }
456 456
457 } // namespace rtc 457 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698