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

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

Issue 1057493005: Revert of base: Replace PurgeAndTruncate with Shrink function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/discardable_shared_memory.h" 5 #include "base/memory/discardable_shared_memory.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <unistd.h> 8 #include <unistd.h>
9 #endif 9 #endif
10 10
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 last_known_usage_ = result.GetLockState() == SharedState::LOCKED 318 last_known_usage_ = result.GetLockState() == SharedState::LOCKED
319 ? current_time 319 ? current_time
320 : result.GetTimestamp(); 320 : result.GetTimestamp();
321 return false; 321 return false;
322 } 322 }
323 323
324 last_known_usage_ = Time(); 324 last_known_usage_ = Time();
325 return true; 325 return true;
326 } 326 }
327 327
328 bool DiscardableSharedMemory::PurgeAndTruncate(Time current_time) {
329 if (!Purge(current_time))
330 return false;
331
332 #if defined(OS_POSIX)
333 // Truncate shared memory to size of SharedState.
334 SharedMemoryHandle handle = shared_memory_.handle();
335 if (SharedMemory::IsHandleValid(handle)) {
336 if (HANDLE_EINTR(ftruncate(handle.fd, sizeof(SharedState))) != 0)
337 DPLOG(ERROR) << "ftruncate() failed";
338 }
339 #endif
340
341 return true;
342 }
343
328 bool DiscardableSharedMemory::IsMemoryResident() const { 344 bool DiscardableSharedMemory::IsMemoryResident() const {
329 DCHECK(shared_memory_.memory()); 345 DCHECK(shared_memory_.memory());
330 346
331 SharedState result(subtle::NoBarrier_Load( 347 SharedState result(subtle::NoBarrier_Load(
332 &SharedStateFromSharedMemory(shared_memory_)->value.i)); 348 &SharedStateFromSharedMemory(shared_memory_)->value.i));
333 349
334 return result.GetLockState() == SharedState::LOCKED || 350 return result.GetLockState() == SharedState::LOCKED ||
335 !result.GetTimestamp().is_null(); 351 !result.GetTimestamp().is_null();
336 } 352 }
337 353
338 void DiscardableSharedMemory::Close() { 354 void DiscardableSharedMemory::Close() {
339 shared_memory_.Unmap(); 355 shared_memory_.Unmap();
340 shared_memory_.Close(); 356 shared_memory_.Close();
341 mapped_size_ = 0; 357 mapped_size_ = 0;
342 } 358 }
343 359
344 #if defined(DISCARDABLE_SHARED_MEMORY_SHRINKING)
345 void DiscardableSharedMemory::Shrink() {
346 #if defined(OS_POSIX)
347 SharedMemoryHandle handle = shared_memory_.handle();
348 if (!SharedMemory::IsHandleValid(handle))
349 return;
350
351 // Truncate shared memory to size of SharedState.
352 if (HANDLE_EINTR(
353 ftruncate(handle.fd, AlignToPageSize(sizeof(SharedState)))) != 0) {
354 DPLOG(ERROR) << "ftruncate() failed";
355 return;
356 }
357 mapped_size_ = 0;
358 #else
359 NOTIMPLEMENTED();
360 #endif
361 }
362 #endif
363
364 Time DiscardableSharedMemory::Now() const { 360 Time DiscardableSharedMemory::Now() const {
365 return Time::Now(); 361 return Time::Now();
366 } 362 }
367 363
368 } // namespace base 364 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_shared_memory.h ('k') | base/memory/discardable_shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698