Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2726)

Unified Diff: base/shared_memory.h

Issue 21063: Transition POSIX shmem to use lockf(), not semaphores. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/shared_memory_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/shared_memory.h
===================================================================
--- base/shared_memory.h (revision 9116)
+++ base/shared_memory.h (working copy)
@@ -24,11 +24,9 @@
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 @@
// 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 @@
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 @@
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);
« no previous file with comments | « no previous file | base/shared_memory_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698