diff options
-rw-r--r-- | base/message_loop.cc | 24 | ||||
-rw-r--r-- | base/message_loop.h | 9 | ||||
-rw-r--r-- | base/message_loop_unittest.cc | 6 |
3 files changed, 18 insertions, 21 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc index aa71d8d..7d2fbff 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -128,7 +128,7 @@ MessageLoop::MessageLoop() : message_hwnd_(NULL), exception_restoration_(false), nestable_tasks_allowed_(true), dispatcher_(NULL), - quit_received_(0), + quit_received_(false), quit_now_(false), task_pump_message_pending_(false), run_depth_(0) { @@ -226,16 +226,6 @@ void MessageLoop::RunInternal(Dispatcher* dispatcher, bool non_blocking) { // and leave messages pending, so don't assert the above fact). RunTraditional(non_blocking); DCHECK(non_blocking || quit_received_ || quit_now_); - // Repost excess kMsgQuit's that were received before we exit. - int excess_quits = quit_received_ - 1; // One is expected. - if (non_blocking || quit_now_) - ++excess_quits; // Any quit is an excess quit. - if (excess_quits > run_depth_ - 1) { - // DCHECK(false); // Someone sent redundant quits. - excess_quits = run_depth_ - 1; - } - while (--excess_quits >= 0) - Quit(); } void MessageLoop::RunTraditional(bool non_blocking) { @@ -255,7 +245,6 @@ void MessageLoop::RunTraditional(bool non_blocking) { more_work_is_plausible |= ProcessNextDeferredTask(); more_work_is_plausible |= ProcessNextObject(); - more_work_is_plausible |= ProcessNextDelayedNonNestableTask(); if (more_work_is_plausible) continue; @@ -266,6 +255,11 @@ void MessageLoop::RunTraditional(bool non_blocking) { if (ProcessSomeTimers()) continue; + // We run delayed non nestable tasks only after all nestable tasks have + // run, to preserve FIFO ordering. + if (ProcessNextDelayedNonNestableTask()) + continue; + if (non_blocking) return; @@ -404,7 +398,11 @@ LRESULT MessageLoop::MessageWndProc(HWND hwnd, UINT message, } case kMsgQuit: { - ++quit_received_; + // TODO(jar): bug 1300541 The following assert should be used, but + // currently too much code actually triggers the assert, especially in + // tests :-(. + //CHECK(!quit_received_); // Discarding a second quit will cause a hang. + quit_received_ = true; return 0; } } diff --git a/base/message_loop.h b/base/message_loop.h index 8d5644329..1610d07 100644 --- a/base/message_loop.h +++ b/base/message_loop.h @@ -353,8 +353,7 @@ class MessageLoop { quit_now_(loop->quit_now_), quit_received_(loop->quit_received_), run_depth_(loop->run_depth_) { - loop->quit_now_ = false; - loop->quit_received_ = 0; + loop->quit_now_ = loop->quit_received_ = false; ++loop->run_depth_; } @@ -369,7 +368,7 @@ class MessageLoop { MessageLoop* loop_; Dispatcher* dispatcher_; bool quit_now_; - int quit_received_; + bool quit_received_; int run_depth_; }; // struct ScopedStateSave @@ -587,8 +586,8 @@ class MessageLoop { bool exception_restoration_; Dispatcher* dispatcher_; - int quit_received_; // The number of kQuitMsg's processed during run. - bool quit_now_; // A dispatcher indicated the message pump should terminate. + bool quit_received_; + bool quit_now_; std::string thread_name_; // A profiling histogram showing the counts of various messages and events. diff --git a/base/message_loop_unittest.cc b/base/message_loop_unittest.cc index 5cf4a99..6c71c5b0 100644 --- a/base/message_loop_unittest.cc +++ b/base/message_loop_unittest.cc @@ -731,7 +731,7 @@ TEST(MessageLoop, NonNestableInNestedLoop) { task->set_nestable(false); MessageLoop::current()->PostTask(FROM_HERE, task); MessageLoop::current()->PostTask(FROM_HERE, new OrderedTasks(&order, 3)); - MessageLoop::current()->PostTask(FROM_HERE, new OrderedTasks(&order, 4)); + MessageLoop::current()->PostTask(FROM_HERE, new QuitTask(&order, 4)); Task* non_nestable_quit = new QuitTask(&order, 5); non_nestable_quit->set_nestable(false); MessageLoop::current()->PostTask(FROM_HERE, non_nestable_quit); @@ -744,8 +744,8 @@ TEST(MessageLoop, NonNestableInNestedLoop) { EXPECT_EQ(order[ 0], TaskItem(PUMPS, 1, true)); EXPECT_EQ(order[ 1], TaskItem(ORDERERD, 3, true)); EXPECT_EQ(order[ 2], TaskItem(ORDERERD, 3, false)); - EXPECT_EQ(order[ 3], TaskItem(ORDERERD, 4, true)); - EXPECT_EQ(order[ 4], TaskItem(ORDERERD, 4, false)); + EXPECT_EQ(order[ 3], TaskItem(QUITMESSAGELOOP, 4, true)); + EXPECT_EQ(order[ 4], TaskItem(QUITMESSAGELOOP, 4, false)); EXPECT_EQ(order[ 5], TaskItem(PUMPS, 1, false)); EXPECT_EQ(order[ 6], TaskItem(ORDERERD, 2, true)); EXPECT_EQ(order[ 7], TaskItem(ORDERERD, 2, false)); |