OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/shared_memory.h" | 5 #include "base/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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 | 73 |
74 // static | 74 // static |
75 SharedMemoryHandle SharedMemory::NULLHandle() { | 75 SharedMemoryHandle SharedMemory::NULLHandle() { |
76 return SharedMemoryHandle(); | 76 return SharedMemoryHandle(); |
77 } | 77 } |
78 | 78 |
79 // static | 79 // static |
80 void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { | 80 void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { |
81 DCHECK(handle.fd >= 0); | 81 DCHECK(handle.fd >= 0); |
82 close(handle.fd); | 82 if (HANDLE_EINTR(close(handle.fd)) < 0) |
| 83 PLOG(ERROR) << "close"; |
83 } | 84 } |
84 | 85 |
85 bool SharedMemory::CreateAndMapAnonymous(uint32 size) { | 86 bool SharedMemory::CreateAndMapAnonymous(uint32 size) { |
86 return CreateAnonymous(size) && Map(size); | 87 return CreateAnonymous(size) && Map(size); |
87 } | 88 } |
88 | 89 |
89 bool SharedMemory::CreateAnonymous(uint32 size) { | 90 bool SharedMemory::CreateAnonymous(uint32 size) { |
90 return CreateNamed("", false, size); | 91 return CreateNamed("", false, size); |
91 } | 92 } |
92 | 93 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 223 } |
223 | 224 |
224 SharedMemoryHandle SharedMemory::handle() const { | 225 SharedMemoryHandle SharedMemory::handle() const { |
225 return FileDescriptor(mapped_file_, false); | 226 return FileDescriptor(mapped_file_, false); |
226 } | 227 } |
227 | 228 |
228 void SharedMemory::Close() { | 229 void SharedMemory::Close() { |
229 Unmap(); | 230 Unmap(); |
230 | 231 |
231 if (mapped_file_ > 0) { | 232 if (mapped_file_ > 0) { |
232 close(mapped_file_); | 233 if (HANDLE_EINTR(close(mapped_file_)) < 0) |
| 234 PLOG(ERROR) << "close"; |
233 mapped_file_ = -1; | 235 mapped_file_ = -1; |
234 } | 236 } |
235 } | 237 } |
236 | 238 |
237 void SharedMemory::Lock() { | 239 void SharedMemory::Lock() { |
238 LockOrUnlockCommon(F_LOCK); | 240 LockOrUnlockCommon(F_LOCK); |
239 } | 241 } |
240 | 242 |
241 void SharedMemory::Unlock() { | 243 void SharedMemory::Unlock() { |
242 LockOrUnlockCommon(F_ULOCK); | 244 LockOrUnlockCommon(F_ULOCK); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 new_handle->fd = new_fd; | 318 new_handle->fd = new_fd; |
317 new_handle->auto_close = true; | 319 new_handle->auto_close = true; |
318 | 320 |
319 if (close_self) | 321 if (close_self) |
320 Close(); | 322 Close(); |
321 | 323 |
322 return true; | 324 return true; |
323 } | 325 } |
324 | 326 |
325 } // namespace base | 327 } // namespace base |
OLD | NEW |