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

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

Issue 1028333002: Chromium -> Mojo roll. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
(Empty)
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.
4
5 #include "base/memory/discardable_memory_shmem.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/memory/discardable_memory_shmem_allocator.h"
9
10 namespace base {
11 namespace internal {
12
13 DiscardableMemoryShmem::DiscardableMemoryShmem(size_t bytes)
14 : chunk_(DiscardableMemoryShmemAllocator::GetInstance()
15 ->AllocateLockedDiscardableMemory(bytes)),
16 is_locked_(true) {
17 DCHECK(chunk_);
18 }
19
20 DiscardableMemoryShmem::~DiscardableMemoryShmem() {
21 if (is_locked_)
22 Unlock();
23 }
24
25 bool DiscardableMemoryShmem::Lock() {
26 DCHECK(!is_locked_);
27 DCHECK(chunk_);
28
29 if (!chunk_->Lock()) {
30 chunk_.reset();
31 return false;
32 }
33
34 is_locked_ = true;
35 return true;
36 }
37
38 void DiscardableMemoryShmem::Unlock() {
39 DCHECK(is_locked_);
40 chunk_->Unlock();
41 is_locked_ = false;
42 }
43
44 void* DiscardableMemoryShmem::Memory() const {
45 DCHECK(is_locked_);
46 return chunk_->Memory();
47 }
48
49 } // namespace internal
50 } // 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