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

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

Issue 18181011: Make a fairer combined message loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes with delayed messages, Bo found some cases were the current cases did not work Created 7 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
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 #include "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL; 90 MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL;
91 91
92 // Create a process-wide unique ID to represent this task in trace events. This 92 // Create a process-wide unique ID to represent this task in trace events. This
93 // will be mangled with a Process ID hash to reduce the likelyhood of colliding 93 // will be mangled with a Process ID hash to reduce the likelyhood of colliding
94 // with MessageLoop pointers on other processes. 94 // with MessageLoop pointers on other processes.
95 uint64 GetTaskTraceID(const PendingTask& task, MessageLoop* loop) { 95 uint64 GetTaskTraceID(const PendingTask& task, MessageLoop* loop) {
96 return (static_cast<uint64>(task.sequence_num) << 32) | 96 return (static_cast<uint64>(task.sequence_num) << 32) |
97 static_cast<uint64>(reinterpret_cast<intptr_t>(loop)); 97 static_cast<uint64>(reinterpret_cast<intptr_t>(loop));
98 } 98 }
99 99
100 bool AlwaysNotifyPump(MessageLoop::Type type) {
brettw 2013/07/10 18:27:03 Can you add a comment for this function? Like what
Kristian Monsen 2013/07/11 23:29:42 Done.
101 #if defined(OS_ANDROID)
102 return type == MessageLoop::TYPE_UI;
103 #else
104 return false;
105 #endif
106 }
107
100 } // namespace 108 } // namespace
101 109
102 //------------------------------------------------------------------------------ 110 //------------------------------------------------------------------------------
103 111
104 #if defined(OS_WIN) 112 #if defined(OS_WIN)
105 113
106 // Upon a SEH exception in this thread, it restores the original unhandled 114 // Upon a SEH exception in this thread, it restores the original unhandled
107 // exception filter. 115 // exception filter.
108 static int SEHFilter(LPTOP_LEVEL_EXCEPTION_FILTER old_filter) { 116 static int SEHFilter(LPTOP_LEVEL_EXCEPTION_FILTER old_filter) {
109 ::SetUnhandledExceptionFilter(old_filter); 117 ::SetUnhandledExceptionFilter(old_filter);
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 // tasks (to faciliate FIFO sorting when two tasks have the same 625 // tasks (to faciliate FIFO sorting when two tasks have the same
618 // delayed_run_time value) and for identifying the task in about:tracing. 626 // delayed_run_time value) and for identifying the task in about:tracing.
619 pending_task->sequence_num = next_sequence_num_++; 627 pending_task->sequence_num = next_sequence_num_++;
620 628
621 TRACE_EVENT_FLOW_BEGIN0("task", "MessageLoop::PostTask", 629 TRACE_EVENT_FLOW_BEGIN0("task", "MessageLoop::PostTask",
622 TRACE_ID_MANGLE(GetTaskTraceID(*pending_task, this))); 630 TRACE_ID_MANGLE(GetTaskTraceID(*pending_task, this)));
623 631
624 bool was_empty = incoming_queue_.empty(); 632 bool was_empty = incoming_queue_.empty();
625 incoming_queue_.push(*pending_task); 633 incoming_queue_.push(*pending_task);
626 pending_task->task.Reset(); 634 pending_task->task.Reset();
627 if (!was_empty) 635 // The Android UI message loop needs to get notified each time
636 // a task is added to the incoming queue.
637 if (!was_empty && !AlwaysNotifyPump(type_))
628 return true; // Someone else should have started the sub-pump. 638 return true; // Someone else should have started the sub-pump.
629 639
630 pump = pump_; 640 pump = pump_;
631 } 641 }
632 // Since the incoming_queue_ may contain a task that destroys this message 642 // Since the incoming_queue_ may contain a task that destroys this message
633 // loop, we cannot exit incoming_queue_lock_ until we are done with |this|. 643 // loop, we cannot exit incoming_queue_lock_ until we are done with |this|.
634 // We use a stack-based reference to the message pump so that we can call 644 // We use a stack-based reference to the message pump so that we can call
635 // ScheduleWork outside of incoming_queue_lock_. 645 // ScheduleWork outside of incoming_queue_lock_.
636 646
637 pump->ScheduleWork(); 647 pump->ScheduleWork();
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 fd, 835 fd,
826 persistent, 836 persistent,
827 mode, 837 mode,
828 controller, 838 controller,
829 delegate); 839 delegate);
830 } 840 }
831 841
832 #endif 842 #endif
833 843
834 } // namespace base 844 } // namespace base
OLDNEW
« no previous file with comments | « base/android/java/src/org/chromium/base/SystemMessageHandler.java ('k') | base/message_loop/message_pump_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698