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

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

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 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/messagequeue.h ('k') | webrtc/base/natsocketfactory.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 #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 kMaxMsgLatency = 150; // 150 ms 30 const uint32_t kMaxMsgLatency = 150; // 150 ms
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 if (fPeekKeep_) { 181 if (fPeekKeep_) {
182 *pmsg = msgPeek_; 182 *pmsg = msgPeek_;
183 fPeekKeep_ = false; 183 fPeekKeep_ = false;
184 return true; 184 return true;
185 } 185 }
186 186
187 // Get w/wait + timer scan / dispatch + socket / event multiplexer dispatch 187 // Get w/wait + timer scan / dispatch + socket / event multiplexer dispatch
188 188
189 int cmsTotal = cmsWait; 189 int cmsTotal = cmsWait;
190 int cmsElapsed = 0; 190 int cmsElapsed = 0;
191 uint32 msStart = Time(); 191 uint32_t msStart = Time();
192 uint32 msCurrent = msStart; 192 uint32_t msCurrent = msStart;
193 while (true) { 193 while (true) {
194 // Check for sent messages 194 // Check for sent messages
195 ReceiveSends(); 195 ReceiveSends();
196 196
197 // Check for posted events 197 // Check for posted events
198 int cmsDelayNext = kForever; 198 int cmsDelayNext = kForever;
199 bool first_pass = true; 199 bool first_pass = true;
200 while (true) { 200 while (true) {
201 // All queue operations need to be locked, but nothing else in this loop 201 // All queue operations need to be locked, but nothing else in this loop
202 // (specifically handling disposed message) can happen inside the crit. 202 // (specifically handling disposed message) can happen inside the crit.
(...skipping 17 matching lines...) Expand all
220 if (msgq_.empty()) { 220 if (msgq_.empty()) {
221 break; 221 break;
222 } else { 222 } else {
223 *pmsg = msgq_.front(); 223 *pmsg = msgq_.front();
224 msgq_.pop_front(); 224 msgq_.pop_front();
225 } 225 }
226 } // crit_ is released here. 226 } // crit_ is released here.
227 227
228 // Log a warning for time-sensitive messages that we're late to deliver. 228 // Log a warning for time-sensitive messages that we're late to deliver.
229 if (pmsg->ts_sensitive) { 229 if (pmsg->ts_sensitive) {
230 int32 delay = TimeDiff(msCurrent, pmsg->ts_sensitive); 230 int32_t delay = TimeDiff(msCurrent, pmsg->ts_sensitive);
231 if (delay > 0) { 231 if (delay > 0) {
232 LOG_F(LS_WARNING) << "id: " << pmsg->message_id << " delay: " 232 LOG_F(LS_WARNING) << "id: " << pmsg->message_id << " delay: "
233 << (delay + kMaxMsgLatency) << "ms"; 233 << (delay + kMaxMsgLatency) << "ms";
234 } 234 }
235 } 235 }
236 // If this was a dispose message, delete it and skip it. 236 // If this was a dispose message, delete it and skip it.
237 if (MQID_DISPOSE == pmsg->message_id) { 237 if (MQID_DISPOSE == pmsg->message_id) {
238 ASSERT(NULL == pmsg->phandler); 238 ASSERT(NULL == pmsg->phandler);
239 delete pmsg->pdata; 239 delete pmsg->pdata;
240 *pmsg = Message(); 240 *pmsg = Message();
(...skipping 28 matching lines...) Expand all
269 if (cmsElapsed >= cmsWait) 269 if (cmsElapsed >= cmsWait)
270 return false; 270 return false;
271 } 271 }
272 } 272 }
273 return false; 273 return false;
274 } 274 }
275 275
276 void MessageQueue::ReceiveSends() { 276 void MessageQueue::ReceiveSends() {
277 } 277 }
278 278
279 void MessageQueue::Post(MessageHandler *phandler, uint32 id, 279 void MessageQueue::Post(MessageHandler* phandler,
280 MessageData *pdata, bool time_sensitive) { 280 uint32_t id,
281 MessageData* pdata,
282 bool time_sensitive) {
281 if (fStop_) 283 if (fStop_)
282 return; 284 return;
283 285
284 // Keep thread safe 286 // Keep thread safe
285 // Add the message to the end of the queue 287 // Add the message to the end of the queue
286 // Signal for the multiplexer to return 288 // Signal for the multiplexer to return
287 289
288 CritScope cs(&crit_); 290 CritScope cs(&crit_);
289 Message msg; 291 Message msg;
290 msg.phandler = phandler; 292 msg.phandler = phandler;
291 msg.message_id = id; 293 msg.message_id = id;
292 msg.pdata = pdata; 294 msg.pdata = pdata;
293 if (time_sensitive) { 295 if (time_sensitive) {
294 msg.ts_sensitive = Time() + kMaxMsgLatency; 296 msg.ts_sensitive = Time() + kMaxMsgLatency;
295 } 297 }
296 msgq_.push_back(msg); 298 msgq_.push_back(msg);
297 ss_->WakeUp(); 299 ss_->WakeUp();
298 } 300 }
299 301
300 void MessageQueue::PostDelayed(int cmsDelay, 302 void MessageQueue::PostDelayed(int cmsDelay,
301 MessageHandler* phandler, 303 MessageHandler* phandler,
302 uint32 id, 304 uint32_t id,
303 MessageData* pdata) { 305 MessageData* pdata) {
304 return DoDelayPost(cmsDelay, TimeAfter(cmsDelay), phandler, id, pdata); 306 return DoDelayPost(cmsDelay, TimeAfter(cmsDelay), phandler, id, pdata);
305 } 307 }
306 308
307 void MessageQueue::PostAt(uint32 tstamp, 309 void MessageQueue::PostAt(uint32_t tstamp,
308 MessageHandler* phandler, 310 MessageHandler* phandler,
309 uint32 id, 311 uint32_t id,
310 MessageData* pdata) { 312 MessageData* pdata) {
311 return DoDelayPost(TimeUntil(tstamp), tstamp, phandler, id, pdata); 313 return DoDelayPost(TimeUntil(tstamp), tstamp, phandler, id, pdata);
312 } 314 }
313 315
314 void MessageQueue::DoDelayPost(int cmsDelay, uint32 tstamp, 316 void MessageQueue::DoDelayPost(int cmsDelay,
315 MessageHandler *phandler, uint32 id, MessageData* pdata) { 317 uint32_t tstamp,
318 MessageHandler* phandler,
319 uint32_t id,
320 MessageData* pdata) {
316 if (fStop_) 321 if (fStop_)
317 return; 322 return;
318 323
319 // Keep thread safe 324 // Keep thread safe
320 // Add to the priority queue. Gets sorted soonest first. 325 // Add to the priority queue. Gets sorted soonest first.
321 // Signal for the multiplexer to return. 326 // Signal for the multiplexer to return.
322 327
323 CritScope cs(&crit_); 328 CritScope cs(&crit_);
324 Message msg; 329 Message msg;
325 msg.phandler = phandler; 330 msg.phandler = phandler;
(...skipping 17 matching lines...) Expand all
343 if (!dmsgq_.empty()) { 348 if (!dmsgq_.empty()) {
344 int delay = TimeUntil(dmsgq_.top().msTrigger_); 349 int delay = TimeUntil(dmsgq_.top().msTrigger_);
345 if (delay < 0) 350 if (delay < 0)
346 delay = 0; 351 delay = 0;
347 return delay; 352 return delay;
348 } 353 }
349 354
350 return kForever; 355 return kForever;
351 } 356 }
352 357
353 void MessageQueue::Clear(MessageHandler *phandler, uint32 id, 358 void MessageQueue::Clear(MessageHandler* phandler,
359 uint32_t id,
354 MessageList* removed) { 360 MessageList* removed) {
355 CritScope cs(&crit_); 361 CritScope cs(&crit_);
356 362
357 // Remove messages with phandler 363 // Remove messages with phandler
358 364
359 if (fPeekKeep_ && msgPeek_.Match(phandler, id)) { 365 if (fPeekKeep_ && msgPeek_.Match(phandler, id)) {
360 if (removed) { 366 if (removed) {
361 removed->push_back(msgPeek_); 367 removed->push_back(msgPeek_);
362 } else { 368 } else {
363 delete msgPeek_.pdata; 369 delete msgPeek_.pdata;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 403 }
398 dmsgq_.container().erase(new_end, dmsgq_.container().end()); 404 dmsgq_.container().erase(new_end, dmsgq_.container().end());
399 dmsgq_.reheap(); 405 dmsgq_.reheap();
400 } 406 }
401 407
402 void MessageQueue::Dispatch(Message *pmsg) { 408 void MessageQueue::Dispatch(Message *pmsg) {
403 pmsg->phandler->OnMessage(pmsg); 409 pmsg->phandler->OnMessage(pmsg);
404 } 410 }
405 411
406 } // namespace rtc 412 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/messagequeue.h ('k') | webrtc/base/natsocketfactory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698