diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-11 00:50:59 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-11 00:50:59 +0000 |
commit | eae9c0623d1800201739b4be146649103a45cd93 (patch) | |
tree | 2ce42f83e18d8a0a618ffd6dbe69b1acade5bda4 /base/shared_memory_posix.cc | |
parent | 26f0821d0a34a79e551213d56054366aab6c70f7 (diff) | |
download | chromium_src-eae9c0623d1800201739b4be146649103a45cd93.zip chromium_src-eae9c0623d1800201739b4be146649103a45cd93.tar.gz chromium_src-eae9c0623d1800201739b4be146649103a45cd93.tar.bz2 |
Order function definitions in base/ according to the header.
BUG=68682
TEST=compiles
Review URL: http://codereview.chromium.org/6085015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/shared_memory_posix.cc')
-rw-r--r-- | base/shared_memory_posix.cc | 125 |
1 files changed, 62 insertions, 63 deletions
diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc index a44581e..843322b 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); while (lockf(mapped_file_, function, 0) < 0) { @@ -311,16 +308,18 @@ void SharedMemory::LockOrUnlockCommon(int function) { } } -void SharedMemory::Lock() { - LockOrUnlockCommon(F_LOCK); -} +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; -void SharedMemory::Unlock() { - LockOrUnlockCommon(F_ULOCK); -} + if (close_self) + Close(); -SharedMemoryHandle SharedMemory::handle() const { - return FileDescriptor(mapped_file_, false); + return true; } } // namespace base |