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

Side by Side Diff: base/message_pump_mac.h

Issue 300044: Change the strategy used to attempt nesting-deferred work to account equally... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « no previous file | base/message_pump_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 // The basis for all native run loops on the Mac is the CFRunLoop. It can be 5 // The basis for all native run loops on the Mac is the CFRunLoop. It can be
6 // used directly, it can be used as the driving force behind the similar 6 // used directly, it can be used as the driving force behind the similar
7 // Foundation NSRunLoop, and it can be used to implement higher-level event 7 // Foundation NSRunLoop, and it can be used to implement higher-level event
8 // loops such as the NSApplication event loop. 8 // loops such as the NSApplication event loop.
9 // 9 //
10 // This file introduces a basic CFRunLoop-based implementation of the 10 // This file introduces a basic CFRunLoop-based implementation of the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly. 47 // in the DoRun method. MessagePumpCFRunLoopBase::Run calls DoRun directly.
48 // This arrangement is used because MessagePumpCFRunLoopBase needs to set 48 // This arrangement is used because MessagePumpCFRunLoopBase needs to set
49 // up and tear down things before and after the "meat" of DoRun. 49 // up and tear down things before and after the "meat" of DoRun.
50 virtual void Run(Delegate* delegate); 50 virtual void Run(Delegate* delegate);
51 virtual void DoRun(Delegate* delegate) = 0; 51 virtual void DoRun(Delegate* delegate) = 0;
52 52
53 virtual void ScheduleWork(); 53 virtual void ScheduleWork();
54 virtual void ScheduleDelayedWork(const Time& delayed_work_time); 54 virtual void ScheduleDelayedWork(const Time& delayed_work_time);
55 55
56 protected: 56 protected:
57 // The thread's run loop. 57 // Accessors for private data members to be used by subclasses.
58 CFRunLoopRef run_loop_; 58 CFRunLoopRef run_loop() const { return run_loop_; }
59 59 int nesting_level() const { return nesting_level_; }
60 // The recursion depth of the currently-executing CFRunLoopRun loop on the 60 int run_nesting_level() const { return run_nesting_level_; }
61 // run loop's thread. 0 if no run loops are running inside of whatever scope
62 // the object was created in.
63 int nesting_level_;
64
65 // The recursion depth (calculated in the same way as nesting_level_) of the
66 // innermost executing CFRunLoopRun loop started by a call to Run.
67 int run_nesting_level_;
68 61
69 private: 62 private:
70 // Timer callback scheduled by ScheduleDelayedWork. This does not do any 63 // Timer callback scheduled by ScheduleDelayedWork. This does not do any
71 // work, but it signals delayed_work_source_ so that delayed work can be 64 // work, but it signals delayed_work_source_ so that delayed work can be
72 // performed within the appropriate priority constraints. 65 // performed within the appropriate priority constraints.
73 static void RunDelayedWorkTimer(CFRunLoopTimerRef timer, void* info); 66 static void RunDelayedWorkTimer(CFRunLoopTimerRef timer, void* info);
74 67
75 // Perform highest-priority work. This is associated with work_source_ 68 // Perform highest-priority work. This is associated with work_source_
76 // signalled by ScheduleWork. The static method calls the instance method; 69 // signalled by ScheduleWork. The static method calls the instance method;
77 // the instance method returns true if work was done. 70 // the instance method returns true if work was done.
(...skipping 11 matching lines...) Expand all
89 // Perform idle-priority work. This is normally called by PreWaitObserver, 82 // Perform idle-priority work. This is normally called by PreWaitObserver,
90 // but is also associated with idle_work_source_. When this function 83 // but is also associated with idle_work_source_. When this function
91 // actually does perform idle work, it will resignal that source. The 84 // actually does perform idle work, it will resignal that source. The
92 // static method calls the instance method; the instance method returns 85 // static method calls the instance method; the instance method returns
93 // true if idle work was done. 86 // true if idle work was done.
94 static void RunIdleWorkSource(void* info); 87 static void RunIdleWorkSource(void* info);
95 bool RunIdleWork(); 88 bool RunIdleWork();
96 89
97 // Perform work that may have been deferred because it was not runnable 90 // Perform work that may have been deferred because it was not runnable
98 // within a nested run loop. This is associated with 91 // within a nested run loop. This is associated with
99 // nesting_deferred_work_source_ and is signalled by EnterExitObserver when 92 // nesting_deferred_work_source_ and is signalled by
100 // a run loop exits, so that an outer loop will be able to perform the 93 // MaybeScheduleNestingDeferredWork when returning from a nested loop,
101 // necessary tasks. The static method calls the instance method; the 94 // so that an outer loop will be able to perform the necessary tasks if it
102 // instance method returns true if anything was done. 95 // permits nestable tasks.
103 static void RunNestingDeferredWorkSource(void* info); 96 static void RunNestingDeferredWorkSource(void* info);
104 bool RunNestingDeferredWork(); 97 bool RunNestingDeferredWork();
105 98
99 // Schedules possible nesting-deferred work to be processed before the run
100 // loop goes to sleep or exits. If this function detects that a nested loop
101 // had run since the previous attempt to schedule nesting-deferred work, it
102 // will schedule a call to RunNestingDeferredWorkSource.
103 void MaybeScheduleNestingDeferredWork();
104
106 // Observer callback responsible for performing idle-priority work, before 105 // Observer callback responsible for performing idle-priority work, before
107 // the run loop goes to sleep. Associated with idle_work_observer_. 106 // the run loop goes to sleep. Associated with idle_work_observer_.
108 static void PreWaitObserver(CFRunLoopObserverRef observer, 107 static void PreWaitObserver(CFRunLoopObserverRef observer,
109 CFRunLoopActivity activity, void* info); 108 CFRunLoopActivity activity, void* info);
110 109
111 // Observer callback called when the run loop starts and stops, at the 110 // Observer callback called when the run loop starts and stops, at the
112 // beginning and end of calls to CFRunLoopRun. This is used to maintain 111 // beginning and end of calls to CFRunLoopRun. This is used to maintain
113 // nesting_level_. Associated with enter_exit_observer_. 112 // nesting_level_. Associated with enter_exit_observer_.
114 static void EnterExitObserver(CFRunLoopObserverRef observer, 113 static void EnterExitObserver(CFRunLoopObserverRef observer,
115 CFRunLoopActivity activity, void* info); 114 CFRunLoopActivity activity, void* info);
116 115
117 // Called by EnterExitObserver after performing maintenance on nesting_level_. 116 // Called by EnterExitObserver after performing maintenance on nesting_level_.
118 // This allows subclasses an opportunity to perform additional processing on 117 // This allows subclasses an opportunity to perform additional processing on
119 // the basis of run loops starting and stopping. 118 // the basis of run loops starting and stopping.
120 virtual void EnterExitRunLoop(CFRunLoopActivity activity); 119 virtual void EnterExitRunLoop(CFRunLoopActivity activity);
121 120
121 // The thread's run loop.
122 CFRunLoopRef run_loop_;
123
122 // The timer, sources, and observers are described above alongside their 124 // The timer, sources, and observers are described above alongside their
123 // callbacks. 125 // callbacks.
124 CFRunLoopTimerRef delayed_work_timer_; 126 CFRunLoopTimerRef delayed_work_timer_;
125 CFRunLoopSourceRef work_source_; 127 CFRunLoopSourceRef work_source_;
126 CFRunLoopSourceRef delayed_work_source_; 128 CFRunLoopSourceRef delayed_work_source_;
127 CFRunLoopSourceRef idle_work_source_; 129 CFRunLoopSourceRef idle_work_source_;
128 CFRunLoopSourceRef nesting_deferred_work_source_; 130 CFRunLoopSourceRef nesting_deferred_work_source_;
129 CFRunLoopObserverRef pre_wait_observer_; 131 CFRunLoopObserverRef pre_wait_observer_;
130 CFRunLoopObserverRef enter_exit_observer_; 132 CFRunLoopObserverRef enter_exit_observer_;
131 133
132 // (weak) Delegate passed as an argument to the innermost Run call. 134 // (weak) Delegate passed as an argument to the innermost Run call.
133 Delegate* delegate_; 135 Delegate* delegate_;
134 136
137 // The recursion depth of the currently-executing CFRunLoopRun loop on the
138 // run loop's thread. 0 if no run loops are running inside of whatever scope
139 // the object was created in.
140 int nesting_level_;
141
142 // The recursion depth (calculated in the same way as nesting_level_) of the
143 // innermost executing CFRunLoopRun loop started by a call to Run.
144 int run_nesting_level_;
145
146 // The deepest (numerically highest) recursion depth encountered since the
147 // most recent attempt to run nesting-deferred work.
148 int deepest_nesting_level_;
149
135 // "Delegateless" work flags are set when work is ready to be performed but 150 // "Delegateless" work flags are set when work is ready to be performed but
136 // must wait until a delegate is available to process it. This can happen 151 // must wait until a delegate is available to process it. This can happen
137 // when a MessagePumpCFRunLoopBase is instantiated and work arrives without 152 // when a MessagePumpCFRunLoopBase is instantiated and work arrives without
138 // any call to Run on the stack. The Run method will check for delegateless 153 // any call to Run on the stack. The Run method will check for delegateless
139 // work on entry and redispatch it as needed once a delegate is available. 154 // work on entry and redispatch it as needed once a delegate is available.
140 bool delegateless_work_; 155 bool delegateless_work_;
141 bool delegateless_delayed_work_; 156 bool delegateless_delayed_work_;
142 bool delegateless_idle_work_; 157 bool delegateless_idle_work_;
143 158
144 DISALLOW_COPY_AND_ASSIGN(MessagePumpCFRunLoopBase); 159 DISALLOW_COPY_AND_ASSIGN(MessagePumpCFRunLoopBase);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // thread. Otherwise, returns a new instance of MessagePumpNSRunLoop. 223 // thread. Otherwise, returns a new instance of MessagePumpNSRunLoop.
209 static MessagePump* Create(); 224 static MessagePump* Create();
210 225
211 private: 226 private:
212 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac); 227 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePumpMac);
213 }; 228 };
214 229
215 } // namespace base 230 } // namespace base
216 231
217 #endif // BASE_MESSAGE_PUMP_MAC_H_ 232 #endif // BASE_MESSAGE_PUMP_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_pump_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698