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

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

Issue 681713002: Update from chromium https://crrev.com/301315 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « base/memory/discardable_memory_shmem_allocator.h ('k') | base/memory/discardable_memory_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_allocator.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/logging.h"
9 #include "base/memory/discardable_shared_memory.h"
10
11 namespace base {
12 namespace {
13
14 // Default allocator implementation that allocates in-process
15 // DiscardableSharedMemory instances.
16 class DiscardableMemoryShmemAllocatorImpl
17 : public DiscardableMemoryShmemAllocator {
18 public:
19 // Overridden from DiscardableMemoryShmemAllocator:
20 virtual scoped_ptr<DiscardableSharedMemory>
21 AllocateLockedDiscardableSharedMemory(size_t size) override {
22 scoped_ptr<DiscardableSharedMemory> memory(new DiscardableSharedMemory);
23 if (!memory->CreateAndMap(size))
24 return scoped_ptr<DiscardableSharedMemory>();
25
26 return memory.Pass();
27 }
28 };
29
30 LazyInstance<DiscardableMemoryShmemAllocatorImpl>::Leaky g_default_allocator =
31 LAZY_INSTANCE_INITIALIZER;
32
33 DiscardableMemoryShmemAllocator* g_allocator = nullptr;
34
35 } // namespace
36
37 // static
38 void DiscardableMemoryShmemAllocator::SetInstance(
39 DiscardableMemoryShmemAllocator* allocator) {
40 DCHECK(allocator);
41
42 // Make sure this function is only called once before the first call
43 // to GetInstance().
44 DCHECK(!g_allocator);
45
46 g_allocator = allocator;
47 }
48
49 // static
50 DiscardableMemoryShmemAllocator*
51 DiscardableMemoryShmemAllocator::GetInstance() {
52 if (!g_allocator)
53 g_allocator = g_default_allocator.Pointer();
54
55 return g_allocator;
56 }
57
58 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_shmem_allocator.h ('k') | base/memory/discardable_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698