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

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

Issue 2496783002: gpu: Reuse existing code for shared memory allocation. (Closed)
Patch Set: . Created 4 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
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 <stddef.h> 9 #include <stddef.h>
10 #include <sys/mman.h> 10 #include <sys/mman.h>
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 DPLOG(ERROR) << "munmap"; 115 DPLOG(ERROR) << "munmap";
116 memory_ = NULL; 116 memory_ = NULL;
117 mapped_size_ = 0; 117 mapped_size_ = 0;
118 return true; 118 return true;
119 } 119 }
120 120
121 SharedMemoryHandle SharedMemory::handle() const { 121 SharedMemoryHandle SharedMemory::handle() const {
122 return FileDescriptor(mapped_file_, false); 122 return FileDescriptor(mapped_file_, false);
123 } 123 }
124 124
125 SharedMemoryHandle SharedMemory::TakeHandle() {
126 FileDescriptor handle(mapped_file_, true);
127 mapped_file_ = -1;
128 memory_ = nullptr;
129 mapped_size_ = 0;
130 return handle;
131 }
132
125 void SharedMemory::Close() { 133 void SharedMemory::Close() {
126 if (mapped_file_ > 0) { 134 if (mapped_file_ > 0) {
127 if (close(mapped_file_) < 0) 135 if (close(mapped_file_) < 0)
128 DPLOG(ERROR) << "close"; 136 DPLOG(ERROR) << "close";
129 mapped_file_ = -1; 137 mapped_file_ = -1;
130 } 138 }
131 } 139 }
132 140
133 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, 141 bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
134 SharedMemoryHandle *new_handle, 142 SharedMemoryHandle *new_handle,
(...skipping 14 matching lines...) Expand all
149 new_handle->auto_close = true; 157 new_handle->auto_close = true;
150 158
151 if (close_self) { 159 if (close_self) {
152 Unmap(); 160 Unmap();
153 Close(); 161 Close();
154 } 162 }
155 return true; 163 return true;
156 } 164 }
157 165
158 } // namespace base 166 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698