| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 SharedMemory::~SharedMemory() { | 59 SharedMemory::~SharedMemory() { |
| 60 Close(); | 60 Close(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // static | 63 // static |
| 64 bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) { | 64 bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) { |
| 65 return handle.fd >= 0; | 65 return handle.fd >= 0; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // static |
| 69 SharedMemoryHandle SharedMemory::NULLHandle() { |
| 70 return SharedMemoryHandle(); |
| 71 } |
| 72 |
| 68 bool SharedMemory::Create(const std::wstring &name, bool read_only, | 73 bool SharedMemory::Create(const std::wstring &name, bool read_only, |
| 69 bool open_existing, size_t size) { | 74 bool open_existing, size_t size) { |
| 70 read_only_ = read_only; | 75 read_only_ = read_only; |
| 71 | 76 |
| 72 int posix_flags = 0; | 77 int posix_flags = 0; |
| 73 posix_flags |= read_only ? O_RDONLY : O_RDWR; | 78 posix_flags |= read_only ? O_RDONLY : O_RDWR; |
| 74 if (!open_existing || mapped_file_ <= 0) | 79 if (!open_existing || mapped_file_ <= 0) |
| 75 posix_flags |= O_CREAT; | 80 posix_flags |= O_CREAT; |
| 76 | 81 |
| 77 if (!CreateOrOpen(name, posix_flags, size)) | 82 if (!CreateOrOpen(name, posix_flags, size)) |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 306 |
| 302 void SharedMemory::Unlock() { | 307 void SharedMemory::Unlock() { |
| 303 LockOrUnlockCommon(F_ULOCK); | 308 LockOrUnlockCommon(F_ULOCK); |
| 304 } | 309 } |
| 305 | 310 |
| 306 SharedMemoryHandle SharedMemory::handle() const { | 311 SharedMemoryHandle SharedMemory::handle() const { |
| 307 return FileDescriptor(mapped_file_, false); | 312 return FileDescriptor(mapped_file_, false); |
| 308 } | 313 } |
| 309 | 314 |
| 310 } // namespace base | 315 } // namespace base |
| OLD | NEW |