summaryrefslogtreecommitdiffstats
path: root/base/shared_memory.h
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-05 19:04:34 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-05 19:04:34 +0000
commitec031eb72100175a7577948b4062432df362fafe (patch)
tree46a39fd13e468a542422e0a7b74de27d69fd9e90 /base/shared_memory.h
parent9a98651859b42474865234e53c861f75b63e70a1 (diff)
downloadchromium_src-ec031eb72100175a7577948b4062432df362fafe.zip
chromium_src-ec031eb72100175a7577948b4062432df362fafe.tar.gz
chromium_src-ec031eb72100175a7577948b4062432df362fafe.tar.bz2
Transition POSIX shmem to use lockf(), not semaphores. Eliminates
resource leak possibility; allows complete sharing of shmem by fd without name. Add actual multiprocess shmem/locking unit test. Fix flaky shmem unit test. agl: please review. Amanda: please look over as you've been here before. Review URL: http://codereview.chromium.org/21063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9235 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/shared_memory.h')
-rw-r--r--base/shared_memory.h19
1 files changed, 12 insertions, 7 deletions
diff --git a/base/shared_memory.h b/base/shared_memory.h
index d96299a..ede36c5 100644
--- a/base/shared_memory.h
+++ b/base/shared_memory.h
@@ -24,11 +24,9 @@ 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;
+// On POSIX, the lock is implemented as a lockf() on the mapped file,
+// so no additional member (or definition of SharedMemoryLock) is
+// needed.
#endif
// Platform abstraction for shared memory. Provides a C++ wrapper
@@ -123,6 +121,12 @@ class SharedMemory {
// Lock the shared memory.
// This is a cross-process lock which may be recursively
// locked by the same thread.
+ // TODO(port):
+ // WARNING: on POSIX the lock only works across processes, not
+ // across threads. 2 threads in the same process can both grab the
+ // lock at the same time. There are several solutions for this
+ // (futex, lockf+anon_semaphore) but none are both clean and common
+ // across Mac and Linux.
void Lock();
// Release the shared memory lock.
@@ -133,6 +137,8 @@ class SharedMemory {
bool CreateOrOpen(const std::wstring &name, int posix_flags, size_t size);
bool FilenameForMemoryName(const std::wstring &memname,
std::wstring *filename);
+ void LockOrUnlockCommon(int function);
+
#endif
bool ShareToProcessCommon(ProcessHandle process,
SharedMemoryHandle* new_handle,
@@ -143,9 +149,8 @@ class SharedMemory {
void* memory_;
bool read_only_;
size_t max_size_;
+#if !defined(OS_POSIX)
SharedMemoryLock lock_;
-#if defined(OS_POSIX)
- std::string sem_name_;
#endif
DISALLOW_EVIL_CONSTRUCTORS(SharedMemory);