diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-04 00:58:39 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-04 00:58:39 +0000 |
commit | 9e51af9018550b6b23802f66469310f5d1790ab9 (patch) | |
tree | 9ab6f3e0532f6d23c2af1d0acc5605ad00876418 /base/shared_memory.h | |
parent | 4c7ca4b8c2ceb6f823474744f035672c8501d23b (diff) | |
download | chromium_src-9e51af9018550b6b23802f66469310f5d1790ab9.zip chromium_src-9e51af9018550b6b23802f66469310f5d1790ab9.tar.gz chromium_src-9e51af9018550b6b23802f66469310f5d1790ab9.tar.bz2 |
Properly honor base::SharedMemory semantics for name="" to mean
new/private shared memory on POSIX. Transition base::SharedMemory
implementation to file/mmap() to prevent leaking of wired kernel
resources and allow easier cleanup. Enable one more shared_memory
unit test for POSIX. Enable stats_table_unittest.cc for Mac, and
modify it so it cleans up.
Review URL: http://codereview.chromium.org/19724
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9114 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/shared_memory.h')
-rw-r--r-- | base/shared_memory.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/base/shared_memory.h b/base/shared_memory.h index ea60fa6..d96299a 100644 --- a/base/shared_memory.h +++ b/base/shared_memory.h @@ -24,6 +24,10 @@ typedef HANDLE SharedMemoryHandle; typedef HANDLE SharedMemoryLock; #elif defined(OS_POSIX) typedef int SharedMemoryHandle; +// TODO(port): these semaphores can leak if we crash, causing +// autobuilder problems. Transition to something easier to clean up +// (e.g. lockf/flock). +// TODO(port): make sure what we transition to is fast enough. typedef sem_t* SharedMemoryLock; #endif @@ -51,12 +55,18 @@ class SharedMemory { // If read_only is true, opens the memory as read-only. // If open_existing is true, and the shared memory already exists, // opens the existing shared memory and ignores the size parameter. + // If name is the empty string, use a unique name. // Returns true on success, false on failure. bool Create(const std::wstring& name, bool read_only, bool open_existing, size_t size); + // Deletes resources associated with a shared memory segment based on name. + // Not all platforms require this call. + bool Delete(const std::wstring& name); + // Opens a shared memory segment based on a name. // If read_only is true, opens for read-only access. + // If name is the empty string, use a unique name. // Returns true on success, false on failure. bool Open(const std::wstring& name, bool read_only); @@ -120,7 +130,9 @@ class SharedMemory { private: #if defined(OS_POSIX) - bool CreateOrOpen(const std::wstring &name, int posix_flags); + bool CreateOrOpen(const std::wstring &name, int posix_flags, size_t size); + bool FilenameForMemoryName(const std::wstring &memname, + std::wstring *filename); #endif bool ShareToProcessCommon(ProcessHandle process, SharedMemoryHandle* new_handle, @@ -132,6 +144,9 @@ class SharedMemory { bool read_only_; size_t max_size_; SharedMemoryLock lock_; +#if defined(OS_POSIX) + std::string sem_name_; +#endif DISALLOW_EVIL_CONSTRUCTORS(SharedMemory); }; |