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

Unified Diff: base/message_loop/message_pump_mac.mm

Issue 333473002: Add a CFRunLoop mode for message loop tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add multimode helpers Created 6 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 | « base/message_loop/message_pump_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_pump_mac.mm
diff --git a/base/message_loop/message_pump_mac.mm b/base/message_loop/message_pump_mac.mm
index 25aac17f2672c78b503f6bd9aa35b8be95a6bcc3..0ab9ab7c467de5128be33444db018ce73d369f7d 100644
--- a/base/message_loop/message_pump_mac.mm
+++ b/base/message_loop/message_pump_mac.mm
@@ -23,8 +23,44 @@
#import <AppKit/AppKit.h>
#endif // !defined(OS_IOS)
+namespace base {
+
namespace {
+void CFRunLoopAddSourceToAllModes(CFRunLoopRef rl, CFRunLoopSourceRef source) {
+ CFRunLoopAddSource(rl, source, kCFRunLoopCommonModes);
+ CFRunLoopAddSource(rl, source, kMessageLoopExclusiveRunLoopMode);
+}
+
+void CFRunLoopRemoveSourceFromAllModes(CFRunLoopRef rl,
+ CFRunLoopSourceRef source) {
+ CFRunLoopRemoveSource(rl, source, kCFRunLoopCommonModes);
+ CFRunLoopRemoveSource(rl, source, kMessageLoopExclusiveRunLoopMode);
+}
+
+void CFRunLoopAddTimerToAllModes(CFRunLoopRef rl, CFRunLoopTimerRef timer) {
+ CFRunLoopAddTimer(rl, timer, kCFRunLoopCommonModes);
+ CFRunLoopAddTimer(rl, timer, kMessageLoopExclusiveRunLoopMode);
+}
+
+void CFRunLoopRemoveTimerFromAllModes(CFRunLoopRef rl,
+ CFRunLoopTimerRef timer) {
+ CFRunLoopRemoveTimer(rl, timer, kCFRunLoopCommonModes);
+ CFRunLoopRemoveTimer(rl, timer, kMessageLoopExclusiveRunLoopMode);
+}
+
+void CFRunLoopAddObserverToAllModes(CFRunLoopRef rl,
+ CFRunLoopObserverRef observer) {
+ CFRunLoopAddObserver(rl, observer, kCFRunLoopCommonModes);
+ CFRunLoopAddObserver(rl, observer, kMessageLoopExclusiveRunLoopMode);
+}
+
+void CFRunLoopRemoveObserverFromAllModes(CFRunLoopRef rl,
+ CFRunLoopObserverRef observer) {
+ CFRunLoopRemoveObserver(rl, observer, kCFRunLoopCommonModes);
+ CFRunLoopRemoveObserver(rl, observer, kMessageLoopExclusiveRunLoopMode);
+}
+
void NoOp(void* info) {
}
@@ -66,7 +102,9 @@ void SetTimerTolerance(CFRunLoopTimerRef timer, CFTimeInterval tolerance) {
} // namespace
-namespace base {
+// static
+const CFStringRef kMessageLoopExclusiveRunLoopMode =
+ CFSTR("kMessageLoopExclusiveRunLoopMode");
// A scoper for autorelease pools created from message pump run loops.
// Avoids dirtying up the ScopedNSAutoreleasePool interface for the rare
@@ -124,9 +162,7 @@ class MessagePumpInstrumentation {
0, // order
&MessagePumpInstrumentation::TimerFired,
&timer_context));
- CFRunLoopAddTimer(CFRunLoopGetCurrent(),
- timer_,
- kCFRunLoopCommonModes);
+ CFRunLoopAddTimerToAllModes(CFRunLoopGetCurrent(), timer_);
}
// Used to track kCFRunLoopEntry.
@@ -332,7 +368,7 @@ MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase()
0, // priority
RunDelayedWorkTimer,
&timer_context);
- CFRunLoopAddTimer(run_loop_, delayed_work_timer_, kCFRunLoopCommonModes);
+ CFRunLoopAddTimerToAllModes(run_loop_, delayed_work_timer_);
CFRunLoopSourceContext source_context = CFRunLoopSourceContext();
source_context.info = this;
@@ -340,20 +376,19 @@ MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase()
work_source_ = CFRunLoopSourceCreate(NULL, // allocator
1, // priority
&source_context);
- CFRunLoopAddSource(run_loop_, work_source_, kCFRunLoopCommonModes);
+ CFRunLoopAddSourceToAllModes(run_loop_, work_source_);
source_context.perform = RunIdleWorkSource;
idle_work_source_ = CFRunLoopSourceCreate(NULL, // allocator
2, // priority
&source_context);
- CFRunLoopAddSource(run_loop_, idle_work_source_, kCFRunLoopCommonModes);
+ CFRunLoopAddSourceToAllModes(run_loop_, idle_work_source_);
source_context.perform = RunNestingDeferredWorkSource;
nesting_deferred_work_source_ = CFRunLoopSourceCreate(NULL, // allocator
0, // priority
&source_context);
- CFRunLoopAddSource(run_loop_, nesting_deferred_work_source_,
- kCFRunLoopCommonModes);
+ CFRunLoopAddSourceToAllModes(run_loop_, nesting_deferred_work_source_);
CFRunLoopObserverContext observer_context = CFRunLoopObserverContext();
observer_context.info = this;
@@ -364,7 +399,7 @@ MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase()
0, // priority
StartOrEndWaitObserver,
&observer_context);
- CFRunLoopAddObserver(run_loop_, pre_wait_observer_, kCFRunLoopCommonModes);
+ CFRunLoopAddObserverToAllModes(run_loop_, pre_wait_observer_);
pre_source_observer_ = CFRunLoopObserverCreate(NULL, // allocator
kCFRunLoopBeforeSources,
@@ -372,7 +407,7 @@ MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase()
0, // priority
PreSourceObserver,
&observer_context);
- CFRunLoopAddObserver(run_loop_, pre_source_observer_, kCFRunLoopCommonModes);
+ CFRunLoopAddObserverToAllModes(run_loop_, pre_source_observer_);
enter_exit_observer_ = CFRunLoopObserverCreate(NULL, // allocator
kCFRunLoopEntry |
@@ -381,36 +416,32 @@ MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase()
0, // priority
EnterExitObserver,
&observer_context);
- CFRunLoopAddObserver(run_loop_, enter_exit_observer_, kCFRunLoopCommonModes);
+ CFRunLoopAddObserverToAllModes(run_loop_, enter_exit_observer_);
}
// Ideally called on the run loop thread. If other run loops were running
// lower on the run loop thread's stack when this object was created, the
// same number of run loops must be running when this object is destroyed.
MessagePumpCFRunLoopBase::~MessagePumpCFRunLoopBase() {
- CFRunLoopRemoveObserver(run_loop_, enter_exit_observer_,
- kCFRunLoopCommonModes);
+ CFRunLoopRemoveObserverFromAllModes(run_loop_, enter_exit_observer_);
CFRelease(enter_exit_observer_);
- CFRunLoopRemoveObserver(run_loop_, pre_source_observer_,
- kCFRunLoopCommonModes);
+ CFRunLoopRemoveObserverFromAllModes(run_loop_, pre_source_observer_);
CFRelease(pre_source_observer_);
- CFRunLoopRemoveObserver(run_loop_, pre_wait_observer_,
- kCFRunLoopCommonModes);
+ CFRunLoopRemoveObserverFromAllModes(run_loop_, pre_wait_observer_);
CFRelease(pre_wait_observer_);
- CFRunLoopRemoveSource(run_loop_, nesting_deferred_work_source_,
- kCFRunLoopCommonModes);
+ CFRunLoopRemoveSourceFromAllModes(run_loop_, nesting_deferred_work_source_);
CFRelease(nesting_deferred_work_source_);
- CFRunLoopRemoveSource(run_loop_, idle_work_source_, kCFRunLoopCommonModes);
+ CFRunLoopRemoveSourceFromAllModes(run_loop_, idle_work_source_);
CFRelease(idle_work_source_);
- CFRunLoopRemoveSource(run_loop_, work_source_, kCFRunLoopCommonModes);
+ CFRunLoopRemoveSourceFromAllModes(run_loop_, work_source_);
CFRelease(work_source_);
- CFRunLoopRemoveTimer(run_loop_, delayed_work_timer_, kCFRunLoopCommonModes);
+ CFRunLoopRemoveTimerFromAllModes(run_loop_, delayed_work_timer_);
CFRelease(delayed_work_timer_);
CFRelease(run_loop_);
@@ -799,11 +830,11 @@ MessagePumpNSRunLoop::MessagePumpNSRunLoop()
quit_source_ = CFRunLoopSourceCreate(NULL, // allocator
0, // priority
&source_context);
- CFRunLoopAddSource(run_loop(), quit_source_, kCFRunLoopCommonModes);
+ CFRunLoopAddSourceToAllModes(run_loop(), quit_source_);
}
MessagePumpNSRunLoop::~MessagePumpNSRunLoop() {
- CFRunLoopRemoveSource(run_loop(), quit_source_, kCFRunLoopCommonModes);
+ CFRunLoopRemoveSourceFromAllModes(run_loop(), quit_source_);
CFRelease(quit_source_);
}
« no previous file with comments | « base/message_loop/message_pump_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698