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

Unified Diff: content/child/child_discardable_shared_memory_manager.cc

Issue 871043003: base: Improve DiscardableSharedMemory support for ashmem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add missing return statement 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 side-by-side diff with in-line comments
Download patch
Index: content/child/child_discardable_shared_memory_manager.cc
diff --git a/content/child/child_discardable_shared_memory_manager.cc b/content/child/child_discardable_shared_memory_manager.cc
index d5b97a06153fec7c0a0dcbacfc7cfba4b20d36a6..7d07e3279e4ec7de996709e4c18f4b13cd677b01 100644
--- a/content/child/child_discardable_shared_memory_manager.cc
+++ b/content/child/child_discardable_shared_memory_manager.cc
@@ -72,10 +72,11 @@ ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
// Attempt to lock |free_span|. Delete span and search free list again
// if locking failed.
- if (!free_span->shared_memory()->Lock(
+ if (free_span->shared_memory()->Lock(
free_span->start() * base::GetPageSize() -
reinterpret_cast<size_t>(free_span->shared_memory()->memory()),
- free_span->length() * base::GetPageSize())) {
+ free_span->length() * base::GetPageSize()) !=
+ base::DiscardableSharedMemory::SUCCESS) {
heap_.DeleteSpan(free_span.Pass());
continue;
}
@@ -114,19 +115,34 @@ ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
bool ChildDiscardableSharedMemoryManager::LockSpan(
DiscardableSharedMemoryHeap::Span* span) {
base::AutoLock lock(lock_);
- return span->shared_memory()->Lock(
- span->start() * base::GetPageSize() -
- reinterpret_cast<size_t>(span->shared_memory()->memory()),
- span->length() * base::GetPageSize());
+
+ size_t offset = span->start() * base::GetPageSize() -
+ reinterpret_cast<size_t>(span->shared_memory()->memory());
+ size_t length = span->length() * base::GetPageSize();
+
+ switch (span->shared_memory()->Lock(offset, length)) {
+ case base::DiscardableSharedMemory::SUCCESS:
+ return true;
+ case base::DiscardableSharedMemory::PURGED:
+ span->shared_memory()->Unlock(offset, length);
+ return false;
+ case base::DiscardableSharedMemory::FAILED:
+ return false;
+ }
+
+ NOTREACHED();
+ return false;
}
void ChildDiscardableSharedMemoryManager::UnlockSpan(
DiscardableSharedMemoryHeap::Span* span) {
base::AutoLock lock(lock_);
- return span->shared_memory()->Unlock(
- span->start() * base::GetPageSize() -
- reinterpret_cast<size_t>(span->shared_memory()->memory()),
- span->length() * base::GetPageSize());
+
+ size_t offset = span->start() * base::GetPageSize() -
+ reinterpret_cast<size_t>(span->shared_memory()->memory());
+ size_t length = span->length() * base::GetPageSize();
+
+ return span->shared_memory()->Unlock(offset, length);
}
bool ChildDiscardableSharedMemoryManager::IsSpanResident(
« no previous file with comments | « base/memory/discardable_shared_memory_unittest.cc ('k') | content/common/host_discardable_shared_memory_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698