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

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

Issue 1497843002: mac: Back discardable shared memory with a Mach primitive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_shared_memory.h" 5 #include "base/memory/discardable_shared_memory.h"
6 6
7 #if defined(OS_POSIX) && !defined(OS_NACL) 7 #if defined(OS_POSIX) && !defined(OS_NACL)
8 // For madvise() which is available on all POSIX compatible systems. 8 // For madvise() which is available on all POSIX compatible systems.
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 #endif 10 #endif
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 DiscardableSharedMemory::~DiscardableSharedMemory() { 116 DiscardableSharedMemory::~DiscardableSharedMemory() {
117 } 117 }
118 118
119 bool DiscardableSharedMemory::CreateAndMap(size_t size) { 119 bool DiscardableSharedMemory::CreateAndMap(size_t size) {
120 CheckedNumeric<size_t> checked_size = size; 120 CheckedNumeric<size_t> checked_size = size;
121 checked_size += AlignToPageSize(sizeof(SharedState)); 121 checked_size += AlignToPageSize(sizeof(SharedState));
122 if (!checked_size.IsValid()) 122 if (!checked_size.IsValid())
123 return false; 123 return false;
124 124
125 #if defined(OS_MACOSX) && !defined(OS_IOS)
126 // DiscardableSharedMemory does not yet support a Mach-implementation, so
127 // force the underlying primitive to be a POSIX fd. https://crbug.com/547239.
128 if (!shared_memory_.CreateAndMapAnonymousPosix(checked_size.ValueOrDie()))
129 return false;
130 #else
131 if (!shared_memory_.CreateAndMapAnonymous(checked_size.ValueOrDie())) 125 if (!shared_memory_.CreateAndMapAnonymous(checked_size.ValueOrDie()))
132 return false; 126 return false;
133 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
134 127
135 mapped_size_ = 128 mapped_size_ =
136 shared_memory_.mapped_size() - AlignToPageSize(sizeof(SharedState)); 129 shared_memory_.mapped_size() - AlignToPageSize(sizeof(SharedState));
137 130
138 locked_page_count_ = AlignToPageSize(mapped_size_) / base::GetPageSize(); 131 locked_page_count_ = AlignToPageSize(mapped_size_) / base::GetPageSize();
139 #if DCHECK_IS_ON() 132 #if DCHECK_IS_ON()
140 for (size_t page = 0; page < locked_page_count_; ++page) 133 for (size_t page = 0; page < locked_page_count_; ++page)
141 locked_pages_.insert(page); 134 locked_pages_.insert(page);
142 #endif 135 #endif
143 136
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 407
415 void DiscardableSharedMemory::Close() { 408 void DiscardableSharedMemory::Close() {
416 shared_memory_.Close(); 409 shared_memory_.Close();
417 } 410 }
418 411
419 Time DiscardableSharedMemory::Now() const { 412 Time DiscardableSharedMemory::Now() const {
420 return Time::Now(); 413 return Time::Now();
421 } 414 }
422 415
423 } // namespace base 416 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698