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
3 // found in the LICENSE file.
5 #include "base/memory/discardable_memory_shmem.h"
7 #include "base/lazy_instance.h"
8 #include "base/memory/discardable_memory_shmem_allocator.h"
13 DiscardableMemoryShmem::DiscardableMemoryShmem(size_t bytes
)
14 : bytes_(bytes
), is_locked_(false) {
17 DiscardableMemoryShmem::~DiscardableMemoryShmem() {
22 bool DiscardableMemoryShmem::Initialize() {
23 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED
;
26 DiscardableMemoryLockStatus
DiscardableMemoryShmem::Lock() {
29 if (chunk_
&& chunk_
->Lock()) {
31 return DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS
;
34 chunk_
= DiscardableMemoryShmemAllocator::GetInstance()
35 ->AllocateLockedDiscardableMemory(bytes_
);
37 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED
;
40 return DISCARDABLE_MEMORY_LOCK_STATUS_PURGED
;
43 void DiscardableMemoryShmem::Unlock() {
50 void* DiscardableMemoryShmem::Memory() const {
53 return chunk_
->Memory();
56 } // namespace internal