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

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

Issue 1164473003: Add methods to base::SharedMemory to replace common SharedMemoryHandle operations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « base/memory/shared_memory.h ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 DCHECK_GE(handle.fd, 0); 101 DCHECK_GE(handle.fd, 0);
102 if (close(handle.fd) < 0) 102 if (close(handle.fd) < 0)
103 DPLOG(ERROR) << "close"; 103 DPLOG(ERROR) << "close";
104 } 104 }
105 105
106 // static 106 // static
107 size_t SharedMemory::GetHandleLimit() { 107 size_t SharedMemory::GetHandleLimit() {
108 return base::GetMaxFds(); 108 return base::GetMaxFds();
109 } 109 }
110 110
111 #if defined(OS_WIN) || defined(OS_POSIX)
Nico 2015/05/29 06:50:23 this is just "everywhere", right?
erikchen 2015/05/29 18:30:24 I guess so. Removed preprocessor conditionals.
112 // static
113 SharedMemoryHandle SharedMemory::ShallowCopyOfHandle(
114 const SharedMemoryHandle& handle) {
115 return handle;
Nico 2015/05/29 06:50:24 The CL you link to doesn't modify this function. I
erikchen 2015/05/29 18:30:24 I think it's semantically important to not use ass
116 }
117 #endif
118
119 #if defined(OS_POSIX)
120 // static
121 SharedMemoryHandle SharedMemory::DeepCopyOfHandle(
Nico 2015/05/29 06:50:24 CloneHandle() maybe?
erikchen 2015/05/29 18:30:24 If you really want me to change the verb, the cano
122 const SharedMemoryHandle& handle,
123 bool clean_up_resources_on_destruction) {
124 int duped_handle = HANDLE_EINTR(dup(handle.fd));
125 if (duped_handle < 0)
126 return base::SharedMemory::NULLHandle();
127 return base::FileDescriptor(duped_handle, clean_up_resources_on_destruction);
128 }
129 #endif
130
111 bool SharedMemory::CreateAndMapAnonymous(size_t size) { 131 bool SharedMemory::CreateAndMapAnonymous(size_t size) {
112 return CreateAnonymous(size) && Map(size); 132 return CreateAnonymous(size) && Map(size);
113 } 133 }
114 134
115 #if !defined(OS_ANDROID) 135 #if !defined(OS_ANDROID)
116 // Chromium mostly only uses the unique/private shmem as specified by 136 // Chromium mostly only uses the unique/private shmem as specified by
117 // "name == L"". The exception is in the StatsTable. 137 // "name == L"". The exception is in the StatsTable.
118 // TODO(jrg): there is no way to "clean up" all unused named shmem if 138 // TODO(jrg): there is no way to "clean up" all unused named shmem if
119 // we restart from a crash. (That isn't a new problem, but it is a problem.) 139 // we restart from a crash. (That isn't a new problem, but it is a problem.)
120 // In case we want to delete it later, it may be useful to save the value 140 // In case we want to delete it later, it may be useful to save the value
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 513
494 if (close_self) { 514 if (close_self) {
495 Unmap(); 515 Unmap();
496 Close(); 516 Close();
497 } 517 }
498 518
499 return true; 519 return true;
500 } 520 }
501 521
502 } // namespace base 522 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698