ACE_RW_Process_Mutex Class Reference

Wrapper for readers/writer locks that exist across processes. More...

#include <RW_Process_Mutex.h>

Collaboration diagram for ACE_RW_Process_Mutex:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_RW_Process_Mutex (const ACE_TCHAR *name=0, int flags=O_CREAT|O_RDWR, mode_t mode=S_IRUSR|S_IWUSR)
 ~ACE_RW_Process_Mutex (void)
int remove (void)
int acquire (void)
int tryacquire (void)
int release (void)
 Release lock.
int acquire_read (void)
int acquire_write (void)
int tryacquire_read (void)
int tryacquire_write (void)
int tryacquire_write_upgrade (void)
const ACE_File_Locklock (void) const
 Return the underlying lock.
void dump (void) const
 Dump the state of an object.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Private Member Functions

const ACE_TCHARunique_name (void)
 Create and return the unique name.

Private Attributes

ACE_TCHAR name_ [ACE_UNIQUE_NAME_LEN]
ACE_File_Lock lock_
 We need this to get the readers/writer semantics...

Detailed Description

Wrapper for readers/writer locks that exist across processes.

Note:
This class uses an ACE_File_Lock as its implementation. Thus, it can only be reliably used between separate processes, rather than threads in the same process. This isn't a limitation of ACE, it's simply the file lock semantics on UNIX and Win32.
Todo:
For systems with pthread_rwlockattr_setpshared one may consider using them to make the mutex faster.

Definition at line 42 of file RW_Process_Mutex.h.


Constructor & Destructor Documentation

ACE_RW_Process_Mutex::ACE_RW_Process_Mutex ( const ACE_TCHAR name = 0,
int  flags = O_CREAT|O_RDWR,
mode_t  mode = S_IRUSR|S_IWUSR 
)

Create a cross-process readers/writer mutex, passing in the optional name, flags and mode ACE_File_Lock. If not specified, a name is generated and flags and mode are set to default platform values.

Definition at line 30 of file RW_Process_Mutex.cpp.

00033   : lock_ (name ? name : unique_name (), flags, mode)
00034 {
00035 // ACE_TRACE ("ACE_RW_Process_Mutex::ACE_RW_Process_Mutex");
00036 }

ACE_RW_Process_Mutex::~ACE_RW_Process_Mutex ( void   ) 

Definition at line 38 of file RW_Process_Mutex.cpp.

00039 {
00040 // ACE_TRACE ("ACE_RW_Process_Mutex::~ACE_RW_Process_Mutex");
00041 }


Member Function Documentation

ACE_INLINE int ACE_RW_Process_Mutex::acquire ( void   ) 

Same as acquire_write(). Acquire lock ownership; blocks until the lock is acquired or the operation fails.

Definition at line 16 of file RW_Process_Mutex.inl.

References ACE_File_Lock::acquire(), and lock_.

00017 {
00018   return this->lock_.acquire ();
00019 }

ACE_INLINE int ACE_RW_Process_Mutex::acquire_read ( void   ) 

Acquire read lock; blocks until the lock is acquired or the operation fails.

Definition at line 37 of file RW_Process_Mutex.inl.

References ACE_File_Lock::acquire_read(), and lock_.

00038 {
00039   return this->lock_.acquire_read ();
00040 }

ACE_INLINE int ACE_RW_Process_Mutex::acquire_write ( void   ) 

Acquire write lock; blocks until the lock is acquired or the operation fails.

Definition at line 44 of file RW_Process_Mutex.inl.

References ACE_File_Lock::acquire_write(), and lock_.

00045 {
00046   return this->lock_.acquire_write ();
00047 }

void ACE_RW_Process_Mutex::dump ( void   )  const

Dump the state of an object.

Definition at line 44 of file RW_Process_Mutex.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_File_Lock::dump(), LM_DEBUG, and lock_.

00045 {
00046 #if defined (ACE_HAS_DUMP)
00047 // ACE_TRACE ("ACE_RW_Process_Mutex::dump");
00048   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00049   this->lock_.dump ();
00050   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00051 #endif /* ACE_HAS_DUMP */
00052 }

ACE_INLINE const ACE_File_Lock & ACE_RW_Process_Mutex::lock ( void   )  const

Return the underlying lock.

Definition at line 71 of file RW_Process_Mutex.inl.

References lock_.

00072 {
00073 // ACE_TRACE ("ACE_RW_Process_Mutex::lock");
00074   return this->lock_;
00075 }

ACE_INLINE int ACE_RW_Process_Mutex::release ( void   ) 

Release lock.

Definition at line 30 of file RW_Process_Mutex.inl.

References lock_, and ACE_File_Lock::release().

00031 {
00032   return this->lock_.release ();
00033 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_RW_Process_Mutex::remove ( void   ) 

Explicitly destroy the mutex. Note that only one thread should call this method since it doesn't protect against race conditions.

Definition at line 9 of file RW_Process_Mutex.inl.

References lock_, and ACE_File_Lock::remove().

00010 {
00011   return this->lock_.remove ();
00012 }

ACE_INLINE int ACE_RW_Process_Mutex::tryacquire ( void   ) 

Same as tryacquire_write(). Try to acquire the lock, but do not block if the lock is not immediately acquired.

Return values:
-1 on failure. If the lock is already held, errno is set to EBUSY.

Definition at line 23 of file RW_Process_Mutex.inl.

References lock_, and ACE_File_Lock::tryacquire().

00024 {
00025   return this->lock_.tryacquire ();
00026 }

ACE_INLINE int ACE_RW_Process_Mutex::tryacquire_read ( void   ) 

Try to acquire the read lock, but do not block if the lock is not immediately acquired.

Return values:
-1 on failure. If the lock is already held, errno is set to EBUSY.

Definition at line 51 of file RW_Process_Mutex.inl.

References lock_, and ACE_File_Lock::tryacquire_read().

00052 {
00053   return this->lock_.tryacquire_read ();
00054 }

ACE_INLINE int ACE_RW_Process_Mutex::tryacquire_write ( void   ) 

Try to acquire the write lock, but do not block if the lock is not immediately acquired.

Return values:
-1 on failure. If the lock is already held, errno is set to EBUSY.

Definition at line 58 of file RW_Process_Mutex.inl.

References lock_, and ACE_File_Lock::tryacquire_write().

00059 {
00060   return this->lock_.tryacquire_write ();
00061 }

ACE_INLINE int ACE_RW_Process_Mutex::tryacquire_write_upgrade ( void   ) 

Attempt to upgrade a read lock to a write lock. Returns 0 on success, -1 on failure.

Definition at line 65 of file RW_Process_Mutex.inl.

References lock_, and ACE_File_Lock::tryacquire_write_upgrade().

00066 {
00067   return this->lock_.tryacquire_write_upgrade ();
00068 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL const ACE_TCHAR * ACE_RW_Process_Mutex::unique_name ( void   )  [private]

Create and return the unique name.

Definition at line 24 of file RW_Process_Mutex.cpp.

References ACE_UNIQUE_NAME_LEN, and ACE::unique_name().

00025 {
00026   ACE::unique_name (this, this->name_, ACE_UNIQUE_NAME_LEN);
00027   return this->name_;
00028 }


Member Data Documentation

ACE_RW_Process_Mutex::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Definition at line 123 of file RW_Process_Mutex.h.

ACE_File_Lock ACE_RW_Process_Mutex::lock_ [private]

We need this to get the readers/writer semantics...

Definition at line 134 of file RW_Process_Mutex.h.

Referenced by acquire(), acquire_read(), acquire_write(), dump(), lock(), release(), remove(), tryacquire(), tryacquire_read(), tryacquire_write(), and tryacquire_write_upgrade().

ACE_TCHAR ACE_RW_Process_Mutex::name_[ACE_UNIQUE_NAME_LEN] [private]

If the user does not provide a name we generate a unique name in this buffer.

Definition at line 128 of file RW_Process_Mutex.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:32 2010 for ACE by  doxygen 1.4.7