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

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

Issue 817653003: Update from https://crrev.com/309717 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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_memory_shmem.h" 5 #include "base/memory/discardable_memory_shmem.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/discardable_memory_shmem_allocator.h" 8 #include "base/memory/discardable_memory_shmem_allocator.h"
9 #include "base/memory/discardable_shared_memory.h" 9 #include "base/memory/discardable_shared_memory.h"
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 void DiscardableMemoryShmem::Unlock() { 83 void DiscardableMemoryShmem::Unlock() {
84 DCHECK(is_locked_); 84 DCHECK(is_locked_);
85 g_manager.Pointer()->ReleaseLock(this); 85 g_manager.Pointer()->ReleaseLock(this);
86 is_locked_ = false; 86 is_locked_ = false;
87 } 87 }
88 88
89 void* DiscardableMemoryShmem::Memory() const { 89 void* DiscardableMemoryShmem::Memory() const {
90 DCHECK(is_locked_); 90 DCHECK(is_locked_);
91 DCHECK(shared_memory_); 91 DCHECK(chunk_);
92 return shared_memory_->memory(); 92 return chunk_->Memory();
93 } 93 }
94 94
95 bool DiscardableMemoryShmem::AllocateAndAcquireLock() { 95 bool DiscardableMemoryShmem::AllocateAndAcquireLock() {
96 if (shared_memory_ && shared_memory_->Lock(0, 0)) 96 if (chunk_ && chunk_->Lock())
97 return true; 97 return true;
98 98
99 // TODO(reveman): Allocate fixed size memory segments and use a free list to 99 chunk_ = DiscardableMemoryShmemAllocator::GetInstance()
100 // improve performance and limit the number of file descriptors used. 100 ->AllocateLockedDiscardableMemory(bytes_);
101 shared_memory_ = DiscardableMemoryShmemAllocator::GetInstance() 101 DCHECK(chunk_);
102 ->AllocateLockedDiscardableSharedMemory(bytes_);
103 DCHECK(shared_memory_);
104 return false; 102 return false;
105 } 103 }
106 104
107 void DiscardableMemoryShmem::ReleaseLock() { 105 void DiscardableMemoryShmem::ReleaseLock() {
108 shared_memory_->Unlock(0, 0); 106 chunk_->Unlock();
109 } 107 }
110 108
111 void DiscardableMemoryShmem::Purge() { 109 void DiscardableMemoryShmem::Purge() {
112 shared_memory_->Purge(Time()); 110 DCHECK(!is_locked_);
113 shared_memory_.reset(); 111 chunk_.reset();
114 } 112 }
115 113
116 bool DiscardableMemoryShmem::IsMemoryResident() const { 114 bool DiscardableMemoryShmem::IsMemoryResident() const {
117 return shared_memory_->IsMemoryResident(); 115 return chunk_->IsMemoryResident();
118 } 116 }
119 117
120 } // namespace internal 118 } // namespace internal
121 } // namespace base 119 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_shmem.h ('k') | base/memory/discardable_memory_shmem_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698