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

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

Issue 2565683003: Share field trial allocator on Mac (Closed)
Patch Set: Use intentionally dummy value and fix comment Created 4 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 | « base/memory/shared_memory_handle.h ('k') | base/metrics/field_trial.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_handle.h" 5 #include "base/memory/shared_memory_handle.h"
6 6
7 #include <mach/mach_vm.h> 7 #include <mach/mach_vm.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 const SharedMemoryHandle& handle) { 60 const SharedMemoryHandle& handle) {
61 if (this == &handle) 61 if (this == &handle)
62 return *this; 62 return *this;
63 63
64 type_ = handle.type_; 64 type_ = handle.type_;
65 CopyRelevantData(handle); 65 CopyRelevantData(handle);
66 return *this; 66 return *this;
67 } 67 }
68 68
69 SharedMemoryHandle SharedMemoryHandle::Duplicate() const { 69 SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
70 if (!IsValid()) 70 switch (type_) {
71 return SharedMemoryHandle(MACH_PORT_NULL, 0, 0); 71 case POSIX: {
72 if (!IsValid())
73 return SharedMemoryHandle();
74 int duped_fd = HANDLE_EINTR(dup(file_descriptor_.fd));
75 if (duped_fd < 0)
76 return SharedMemoryHandle();
77 return SharedMemoryHandle(FileDescriptor(duped_fd, true));
78 }
79 case MACH: {
80 if (!IsValid())
81 return SharedMemoryHandle(MACH_PORT_NULL, 0, 0);
72 82
73 // Increment the ref count. 83 // Increment the ref count.
74 kern_return_t kr = mach_port_mod_refs(mach_task_self(), memory_object_, 84 kern_return_t kr = mach_port_mod_refs(mach_task_self(), memory_object_,
75 MACH_PORT_RIGHT_SEND, 1); 85 MACH_PORT_RIGHT_SEND, 1);
76 DCHECK_EQ(kr, KERN_SUCCESS); 86 DCHECK_EQ(kr, KERN_SUCCESS);
77 SharedMemoryHandle handle(*this); 87 SharedMemoryHandle handle(*this);
78 handle.SetOwnershipPassesToIPC(true); 88 handle.SetOwnershipPassesToIPC(true);
79 return handle; 89 return handle;
90 }
91 }
80 } 92 }
81 93
82 bool SharedMemoryHandle::operator==(const SharedMemoryHandle& handle) const { 94 bool SharedMemoryHandle::operator==(const SharedMemoryHandle& handle) const {
83 if (!IsValid() && !handle.IsValid()) 95 if (!IsValid() && !handle.IsValid())
84 return true; 96 return true;
85 97
86 if (type_ != handle.type_) 98 if (type_ != handle.type_)
87 return false; 99 return false;
88 100
89 switch (type_) { 101 switch (type_) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 case MACH: 210 case MACH:
199 memory_object_ = handle.memory_object_; 211 memory_object_ = handle.memory_object_;
200 size_ = handle.size_; 212 size_ = handle.size_;
201 pid_ = handle.pid_; 213 pid_ = handle.pid_;
202 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_; 214 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_;
203 break; 215 break;
204 } 216 }
205 } 217 }
206 218
207 } // namespace base 219 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_handle.h ('k') | base/metrics/field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698