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

Side by Side Diff: base/message_loop/message_loop.h

Issue 395913006: High resolution timer fix for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more cleanup Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 364
365 protected: 365 protected:
366 virtual ~TaskObserver(); 366 virtual ~TaskObserver();
367 }; 367 };
368 368
369 // These functions can only be called on the same thread that |this| is 369 // These functions can only be called on the same thread that |this| is
370 // running on. 370 // running on.
371 void AddTaskObserver(TaskObserver* task_observer); 371 void AddTaskObserver(TaskObserver* task_observer);
372 void RemoveTaskObserver(TaskObserver* task_observer); 372 void RemoveTaskObserver(TaskObserver* task_observer);
373 373
374 // When we go into high resolution timer mode, we will stay in hi-res mode
375 // for at least 1s.
376 static const int kHighResolutionTimerModeLeaseTimeMs = 1000;
377
378 #if defined(OS_WIN) 374 #if defined(OS_WIN)
379 void set_os_modal_loop(bool os_modal_loop) { 375 void set_os_modal_loop(bool os_modal_loop) {
380 os_modal_loop_ = os_modal_loop; 376 os_modal_loop_ = os_modal_loop;
381 } 377 }
382 378
383 bool os_modal_loop() const { 379 bool os_modal_loop() const {
384 return os_modal_loop_; 380 return os_modal_loop_;
385 } 381 }
386 #endif // OS_WIN 382 #endif // OS_WIN
387 383
388 // Can only be called from the thread that owns the MessageLoop. 384 // Can only be called from the thread that owns the MessageLoop.
389 bool is_running() const; 385 bool is_running() const;
390 386
391 // Returns true if the message loop has high resolution timers enabled. 387 // Returns true if the message loop has high resolution timers enabled.
392 // Provided for testing. 388 // Provided for testing.
393 bool IsHighResolutionTimerEnabledForTesting(); 389 bool HasHighResolutionTasks();
394 390
395 // Returns true if the message loop is "idle". Provided for testing. 391 // Returns true if the message loop is "idle". Provided for testing.
396 bool IsIdleForTesting(); 392 bool IsIdleForTesting();
397 393
398 //---------------------------------------------------------------------------- 394 //----------------------------------------------------------------------------
399 protected: 395 protected:
400 scoped_ptr<MessagePump> pump_; 396 scoped_ptr<MessagePump> pump_;
401 397
402 private: 398 private:
403 friend class internal::IncomingTaskQueue; 399 friend class internal::IncomingTaskQueue;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 442
447 // Add occurrence of event to our histogram, so that we can see what is being 443 // Add occurrence of event to our histogram, so that we can see what is being
448 // done in a specific MessageLoop instance (i.e., specific thread). 444 // done in a specific MessageLoop instance (i.e., specific thread).
449 // If message_histogram_ is NULL, this is a no-op. 445 // If message_histogram_ is NULL, this is a no-op.
450 void HistogramEvent(int event); 446 void HistogramEvent(int event);
451 447
452 // MessagePump::Delegate methods: 448 // MessagePump::Delegate methods:
453 virtual bool DoWork() OVERRIDE; 449 virtual bool DoWork() OVERRIDE;
454 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; 450 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE;
455 virtual bool DoIdleWork() OVERRIDE; 451 virtual bool DoIdleWork() OVERRIDE;
452 virtual void UpdateTimerGranularity() OVERRIDE;
456 453
457 const Type type_; 454 const Type type_;
458 455
459 // A list of tasks that need to be processed by this instance. Note that 456 // A list of tasks that need to be processed by this instance. Note that
460 // this queue is only accessed (push/pop) by our current thread. 457 // this queue is only accessed (push/pop) by our current thread.
461 TaskQueue work_queue_; 458 TaskQueue work_queue_;
462 459
460 // How many high resolution tasks are in the pending task queue. This value
461 // increases by N every time we call ReloadWorkQueue() and decreases by 1
462 // every time we call RunTask() if the task needs a high resolution timer.
463 int pending_high_res_tasks_;
464
463 // Contains delayed tasks, sorted by their 'delayed_run_time' property. 465 // Contains delayed tasks, sorted by their 'delayed_run_time' property.
464 DelayedTaskQueue delayed_work_queue_; 466 DelayedTaskQueue delayed_work_queue_;
465 467
466 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. 468 // A recent snapshot of Time::Now(), used to check delayed_work_queue_.
467 TimeTicks recent_time_; 469 TimeTicks recent_time_;
468 470
469 // A queue of non-nestable tasks that we had to defer because when it came 471 // A queue of non-nestable tasks that we had to defer because when it came
470 // time to execute them we were in a nested message loop. They will execute 472 // time to execute them we were in a nested message loop. They will execute
471 // once we're out of nested message loops. 473 // once we're out of nested message loops.
472 TaskQueue deferred_non_nestable_work_queue_; 474 TaskQueue deferred_non_nestable_work_queue_;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 655
654 // Do not add any member variables to MessageLoopForIO! This is important b/c 656 // Do not add any member variables to MessageLoopForIO! This is important b/c
655 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 657 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
656 // data that you need should be stored on the MessageLoop's pump_ instance. 658 // data that you need should be stored on the MessageLoop's pump_ instance.
657 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 659 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
658 MessageLoopForIO_should_not_have_extra_member_variables); 660 MessageLoopForIO_should_not_have_extra_member_variables);
659 661
660 } // namespace base 662 } // namespace base
661 663
662 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 664 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698