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

Unified Diff: base/message_loop/message_loop.h

Issue 17567007: Made MessagePump a non-thread safe class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved incoming_queue_ to MessageLoopProxyImpl Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/message_loop/message_loop.cc » ('j') | base/message_loop/message_loop_proxy_impl.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_loop.h
diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h
index e765cef6a3e0b51b574a0140794c026e2e8f45eb..24417afa6a9a099bf096cf8a2184007bbd857449 100644
--- a/base/message_loop/message_loop.h
+++ b/base/message_loop/message_loop.h
@@ -13,6 +13,7 @@
#include "base/callback_forward.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/message_loop/message_pump.h"
#include "base/observer_list.h"
@@ -47,6 +48,7 @@ namespace base {
class HistogramBase;
class MessageLoopLockTest;
+class MessageLoopProxyImpl;
class RunLoop;
class ThreadTaskRunnerHandle;
#if defined(OS_ANDROID)
@@ -282,9 +284,7 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
const std::string& thread_name() const { return thread_name_; }
// Gets the message loop proxy associated with this message loop.
- scoped_refptr<MessageLoopProxy> message_loop_proxy() {
- return message_loop_proxy_.get();
- }
+ scoped_refptr<MessageLoopProxy> message_loop_proxy();
// Enables or disables the recursive task processing. This happens in the case
// of recursive message loops. Some unwanted message loop may occurs when
@@ -359,23 +359,10 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
void AddTaskObserver(TaskObserver* task_observer);
void RemoveTaskObserver(TaskObserver* task_observer);
- // Returns true if the message loop has high resolution timers enabled.
- // Provided for testing.
- bool high_resolution_timers_enabled() {
-#if defined(OS_WIN)
- return !high_resolution_timer_expiration_.is_null();
-#else
- return true;
-#endif
- }
-
// When we go into high resolution timer mode, we will stay in hi-res mode
// for at least 1s.
static const int kHighResolutionTimerModeLeaseTimeMs = 1000;
- // Asserts that the MessageLoop is "idle".
- void AssertIdle() const;
-
#if defined(OS_WIN)
void set_os_modal_loop(bool os_modal_loop) {
os_modal_loop_ = os_modal_loop;
@@ -389,6 +376,13 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
// Can only be called from the thread that owns the MessageLoop.
bool is_running() const;
+ // Returns true if the message loop has high resolution timers enabled.
+ // Provided for testing.
+ bool IsHishResolutionTimersEnabledForTest();
+
+ // Returns true if the message loop is "idle". Provided for testing.
+ bool IsIdleForTest();
+
//----------------------------------------------------------------------------
protected:
@@ -402,11 +396,12 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
}
#endif
- scoped_refptr<MessagePump> pump_;
+ scoped_ptr<MessagePump> pump_;
private:
friend class RunLoop;
friend class MessageLoopLockTest;
+ friend class MessageLoopProxyImpl;
// A function to encapsulate all the exception handling capability in the
// stacks around the running of a main message loop. It will run the message
@@ -436,34 +431,19 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
// Adds the pending task to delayed_work_queue_.
void AddToDelayedWorkQueue(const PendingTask& pending_task);
- // This function attempts to add pending task to our incoming_queue_.
- // The append can only possibly fail when |use_try_lock| is true.
- //
- // When |use_try_lock| is true, then this call will avoid blocking if
- // the related lock is already held, and will in that case (when the
- // lock is contended) fail to perform the append, and will return false.
- //
- // If the call succeeds to append to the queue, then this call
- // will return true.
- //
- // In all cases, the caller retains ownership of |pending_task|, but this
- // function will reset the value of pending_task->task. This is needed to
- // ensure that the posting call stack does not retain pending_task->task
- // beyond this function call.
- bool AddToIncomingQueue(PendingTask* pending_task, bool use_try_lock);
-
- // Load tasks from the incoming_queue_ into work_queue_ if the latter is
- // empty. The former requires a lock to access, while the latter is directly
- // accessible on this thread.
- void ReloadWorkQueue();
-
// Delete tasks that haven't run yet without running them. Used in the
// destructor to make sure all the task's destructors get called. Returns
// true if some work was done.
bool DeletePendingTasks();
- // Calculates the time at which a PendingTask should run.
- TimeTicks CalculateDelayedRuntime(TimeDelta delay);
+ // Wakes up the message pump. Can be called on any thread. The caller is
+ // resonsible for synchronizing StartPump() calls.
rvargas (doing something else) 2013/06/28 22:59:44 typo: responsible
alexeypa (please no reviews) 2013/07/03 18:56:48 Done.
+ void StartPump();
rvargas (doing something else) 2013/06/28 22:59:44 nit: Maybe WakeUpPump()? RestartPump()? StartPump
alexeypa (please no reviews) 2013/07/03 18:56:48 Done.
+
+ // Creates a process-wide unique ID to represent this task in trace events.
+ // This will be mangled with a Process ID hash to reduce the likelyhood of
+ // colliding with MessageLoop pointers on other processes.
+ uint64 GetTaskTraceID(const PendingTask& task);
// Start recording histogram info about events and action IF it was enabled
// and IF the statistics recorder can accept a registration of our histogram.
@@ -508,30 +488,18 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
// A profiling histogram showing the counts of various messages and events.
HistogramBase* message_histogram_;
- // An incoming queue of tasks that are acquired under a mutex for processing
- // on this instance's thread. These tasks have not yet been sorted out into
- // items for our work_queue_ vs delayed_work_queue_.
- TaskQueue incoming_queue_;
- // Protect access to incoming_queue_.
- mutable Lock incoming_queue_lock_;
-
- RunLoop* run_loop_;
-
#if defined(OS_WIN)
- TimeTicks high_resolution_timer_expiration_;
// Should be set to true before calling Windows APIs like TrackPopupMenu, etc
// which enter a modal message loop.
bool os_modal_loop_;
rvargas (doing something else) 2013/06/28 22:59:44 Now that you're moving variables do you mind keepi
alexeypa (please no reviews) 2013/07/03 18:56:48 Done.
#endif
- // The next sequence number to use for delayed tasks. Updating this counter is
- // protected by incoming_queue_lock_.
- int next_sequence_num_;
+ RunLoop* run_loop_;
ObserverList<TaskObserver> task_observers_;
- // The message loop proxy associated with this message loop, if one exists.
- scoped_refptr<MessageLoopProxy> message_loop_proxy_;
+ // The message loop proxy associated with this message loop.
+ scoped_refptr<MessageLoopProxyImpl> message_loop_proxy_;
scoped_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_;
template <class T, class R> friend class base::subtle::DeleteHelperInternal;
« no previous file with comments | « no previous file | base/message_loop/message_loop.cc » ('j') | base/message_loop/message_loop_proxy_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698