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

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

Issue 871043003: base: Improve DiscardableSharedMemory support for ashmem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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_allocator.h" 5 #include "base/memory/discardable_memory_shmem_allocator.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/discardable_shared_memory.h" 9 #include "base/memory/discardable_shared_memory.h"
10 10
11 namespace base { 11 namespace base {
12 namespace { 12 namespace {
13 13
14 class DiscardableMemoryShmemChunkImpl : public DiscardableMemoryShmemChunk { 14 class DiscardableMemoryShmemChunkImpl : public DiscardableMemoryShmemChunk {
15 public: 15 public:
16 explicit DiscardableMemoryShmemChunkImpl( 16 explicit DiscardableMemoryShmemChunkImpl(
17 scoped_ptr<DiscardableSharedMemory> shared_memory) 17 scoped_ptr<DiscardableSharedMemory> shared_memory)
18 : shared_memory_(shared_memory.Pass()) {} 18 : shared_memory_(shared_memory.Pass()) {}
19 19
20 // Overridden from DiscardableMemoryShmemChunk: 20 // Overridden from DiscardableMemoryShmemChunk:
21 bool Lock() override { return shared_memory_->Lock(0, 0); } 21 bool Lock() override {
22 auto result = shared_memory_->Lock(0, 0);
23 DCHECK_NE(result, DiscardableSharedMemory::PURGED);
24 return result == DiscardableSharedMemory::SUCCESS;
25 }
22 void Unlock() override { shared_memory_->Unlock(0, 0); } 26 void Unlock() override { shared_memory_->Unlock(0, 0); }
23 void* Memory() const override { return shared_memory_->memory(); } 27 void* Memory() const override { return shared_memory_->memory(); }
24 bool IsMemoryResident() const override { 28 bool IsMemoryResident() const override {
25 return shared_memory_->IsMemoryResident(); 29 return shared_memory_->IsMemoryResident();
26 } 30 }
27 31
28 private: 32 private:
29 scoped_ptr<DiscardableSharedMemory> shared_memory_; 33 scoped_ptr<DiscardableSharedMemory> shared_memory_;
30 34
31 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl); 35 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // static 73 // static
70 DiscardableMemoryShmemAllocator* 74 DiscardableMemoryShmemAllocator*
71 DiscardableMemoryShmemAllocator::GetInstance() { 75 DiscardableMemoryShmemAllocator::GetInstance() {
72 if (!g_allocator) 76 if (!g_allocator)
73 g_allocator = g_default_allocator.Pointer(); 77 g_allocator = g_default_allocator.Pointer();
74 78
75 return g_allocator; 79 return g_allocator;
76 } 80 }
77 81
78 } // namespace base 82 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/memory/discardable_shared_memory.h » ('j') | base/memory/discardable_shared_memory.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698