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

Side by Side Diff: base/memory/memory_pressure_monitor_mac.cc

Issue 2877573002: [Mac] Fix race condition in memory pressure level reporting. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/memory/memory_pressure_monitor_mac.h" 5 #include "base/memory/memory_pressure_monitor_mac.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h> 7 #include <CoreFoundation/CoreFoundation.h>
8 8
9 #include <dlfcn.h> 9 #include <dlfcn.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 161 }
162 162
163 MemoryPressureListener::MemoryPressureLevel 163 MemoryPressureListener::MemoryPressureLevel
164 MemoryPressureMonitor::GetCurrentPressureLevel() { 164 MemoryPressureMonitor::GetCurrentPressureLevel() {
165 return last_pressure_level_; 165 return last_pressure_level_;
166 } 166 }
167 167
168 void MemoryPressureMonitor::OnMemoryPressureChanged( 168 void MemoryPressureMonitor::OnMemoryPressureChanged(
169 dispatch_source_s* event_source, 169 dispatch_source_s* event_source,
170 const MemoryPressureMonitor::DispatchCallback& dispatch_callback) { 170 const MemoryPressureMonitor::DispatchCallback& dispatch_callback) {
171 // Get the Chrome-equvialent memory pressure level. 171 // The OS has sent a notification that the memory pressure level has changed.
172 int mac_memory_pressure_level = dispatch_source_get_data(event_source); 172 // Go through the normal memory pressure level checking mechanism so that
173 MemoryPressureListener::MemoryPressureLevel memory_pressure_level = 173 // last_pressure_level_ and UMA get updated to the current value.
174 MemoryPressureLevelForMacMemoryPressureLevel(mac_memory_pressure_level); 174 UpdatePressureLevel();
175 175
176 // Run the callback that's waiting on memory pressure change notifications. 176 // Run the callback that's waiting on memory pressure change notifications.
177 // Note that we don't bother with updating |last_pressure_level_| or 177 // The convention is to not send notifiations on memory pressure returning to
178 // causing memory pressure stats to be sent to UMA. Memory pressure change 178 // normal.
179 // notifications are delayed on the Mac, so the current actual memory pressure 179 if (last_pressure_level_ !=
180 // level may be different than the incoming pressure level from the event.
181 //
182 // In general we don't want to take action (such as freeing memory) on
183 // memory pressure change events, but that's how the current system is
184 // designed. Given that it's incorrect to act on either stale or current
185 // pressure level info, it's not clear which level is better to send. For
186 // now stick with how it's been implemented to date, which is to send the
187 // stale value.
188 if (memory_pressure_level !=
189 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) 180 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE)
190 dispatch_callback.Run(memory_pressure_level); 181 dispatch_callback.Run(last_pressure_level_);
191 } 182 }
192 183
193 void MemoryPressureMonitor::SetDispatchCallback( 184 void MemoryPressureMonitor::SetDispatchCallback(
194 const DispatchCallback& callback) { 185 const DispatchCallback& callback) {
195 dispatch_callback_ = callback; 186 dispatch_callback_ = callback;
196 } 187 }
197 188
198 } // namespace mac 189 } // namespace mac
199 } // namespace base 190 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698