diff options
author | Kristian Monsen <kristianm@google.com> | 2011-05-31 20:30:28 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-06-14 20:31:41 -0700 |
commit | 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801 (patch) | |
tree | 382278a54ce7a744d62fa510a9a80688cc12434b /base/shared_memory_posix.cc | |
parent | c4becdd46e31d261b930e4b5a539cbc1d45c23a6 (diff) | |
download | external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.zip external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.gz external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.bz2 |
Merge Chromium.org at r11.0.672.0: Initial merge by git.
Change-Id: I8b4aaf611a2a405fe3fe10e8a94ea7658645c192
Diffstat (limited to 'base/shared_memory_posix.cc')
-rw-r--r-- | base/shared_memory_posix.cc | 123 |
1 files changed, 66 insertions, 57 deletions
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc index e83b982..5ac7597 100644 --- a/base/shared_memory_posix.cc +++ b/base/shared_memory_posix.cc @@ -196,24 +196,52 @@ bool SharedMemory::Open(const std::string& name, bool read_only) { return PrepareMapFile(fp); } -// For the given shmem named |mem_name|, return a filename to mmap() -// (and possibly create). Modifies |filename|. Return false on -// error, or true of we are happy. -bool SharedMemory::FilePathForMemoryName(const std::string& mem_name, - FilePath* path) { - // mem_name will be used for a filename; make sure it doesn't - // contain anything which will confuse us. - DCHECK(mem_name.find('/') == std::string::npos); - DCHECK(mem_name.find('\0') == std::string::npos); +bool SharedMemory::Map(uint32 bytes) { + if (mapped_file_ == -1) + return false; - FilePath temp_dir; - if (!file_util::GetShmemTempDir(&temp_dir)) + memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), + MAP_SHARED, mapped_file_, 0); + + if (memory_) + mapped_size_ = bytes; + + bool mmap_succeeded = (memory_ != (void*)-1); + DCHECK(mmap_succeeded) << "Call to mmap failed, errno=" << errno; + return mmap_succeeded; +} + +bool SharedMemory::Unmap() { + if (memory_ == NULL) return false; - *path = temp_dir.AppendASCII("com.google.chrome.shmem." + mem_name); + munmap(memory_, mapped_size_); + memory_ = NULL; + mapped_size_ = 0; return true; } +SharedMemoryHandle SharedMemory::handle() const { + return FileDescriptor(mapped_file_, false); +} + +void SharedMemory::Close() { + Unmap(); + + if (mapped_file_ > 0) { + close(mapped_file_); + mapped_file_ = -1; + } +} + +void SharedMemory::Lock() { + LockOrUnlockCommon(F_LOCK); +} + +void SharedMemory::Unlock() { + LockOrUnlockCommon(F_ULOCK); +} + bool SharedMemory::PrepareMapFile(FILE *fp) { DCHECK(mapped_file_ == -1); if (fp == NULL) return false; @@ -243,55 +271,24 @@ bool SharedMemory::PrepareMapFile(FILE *fp) { return true; } -bool SharedMemory::Map(uint32 bytes) { - if (mapped_file_ == -1) - return false; - - memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), - MAP_SHARED, mapped_file_, 0); - - if (memory_) - mapped_size_ = bytes; - - bool mmap_succeeded = (memory_ != (void*)-1); - DCHECK(mmap_succeeded) << "Call to mmap failed, errno=" << errno; - return mmap_succeeded; -} +// For the given shmem named |mem_name|, return a filename to mmap() +// (and possibly create). Modifies |filename|. Return false on +// error, or true of we are happy. +bool SharedMemory::FilePathForMemoryName(const std::string& mem_name, + FilePath* path) { + // mem_name will be used for a filename; make sure it doesn't + // contain anything which will confuse us. + DCHECK(mem_name.find('/') == std::string::npos); + DCHECK(mem_name.find('\0') == std::string::npos); -bool SharedMemory::Unmap() { - if (memory_ == NULL) + FilePath temp_dir; + if (!file_util::GetShmemTempDir(&temp_dir)) return false; - munmap(memory_, mapped_size_); - memory_ = NULL; - mapped_size_ = 0; - return true; -} - -bool SharedMemory::ShareToProcessCommon(ProcessHandle process, - SharedMemoryHandle *new_handle, - bool close_self) { - const int new_fd = dup(mapped_file_); - DCHECK(new_fd >= 0); - new_handle->fd = new_fd; - new_handle->auto_close = true; - - if (close_self) - Close(); - + *path = temp_dir.AppendASCII("com.google.chrome.shmem." + mem_name); return true; } - -void SharedMemory::Close() { - Unmap(); - - if (mapped_file_ > 0) { - close(mapped_file_); - mapped_file_ = -1; - } -} - void SharedMemory::LockOrUnlockCommon(int function) { DCHECK(mapped_file_ >= 0); #if !defined(ANDROID) @@ -313,6 +310,7 @@ void SharedMemory::LockOrUnlockCommon(int function) { #endif } +<<<<<<< HEAD void SharedMemory::Lock() { #if !defined(ANDROID) LockOrUnlockCommon(F_LOCK); @@ -324,9 +322,20 @@ void SharedMemory::Unlock() { LockOrUnlockCommon(F_ULOCK); #endif } +======= +bool SharedMemory::ShareToProcessCommon(ProcessHandle process, + SharedMemoryHandle *new_handle, + bool close_self) { + const int new_fd = dup(mapped_file_); + DCHECK(new_fd >= 0); + new_handle->fd = new_fd; + new_handle->auto_close = true; -SharedMemoryHandle SharedMemory::handle() const { - return FileDescriptor(mapped_file_, false); + if (close_self) + Close(); +>>>>>>> chromium.org at r11.0.672.0 + + return true; } } // namespace base |