Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_RW_Mutex Class Reference

Wrapper for readers/writer locks. More...

#include <Synch.h>

Inheritance diagram for ACE_RW_Mutex:

Inheritance graph
[legend]
List of all members.

Public Methods

 ACE_RW_Mutex (int type=USYNC_THREAD, const ACE_TCHAR *name=0, void *arg=0)
 Initialize a readers/writer lock. More...

 ~ACE_RW_Mutex (void)
 Implicitly destroy a readers/writer lock. More...

int remove (void)
int acquire_read (void)
 Acquire a read lock, but block if a writer hold the lock. More...

int acquire_write (void)
 Acquire a write lock, but block if any readers or a writer hold the lock. More...

int tryacquire_read (void)
int tryacquire_write (void)
 Conditionally acquire a write lock (i.e., won't block). More...

int tryacquire_write_upgrade (void)
int acquire (void)
int tryacquire (void)
int release (void)
 Unlock a readers/writer lock. More...

const ACE_rwlock_t & lock (void) const
 Return the underlying lock. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Protected Attributes

ACE_rwlock_t lock_
 Readers/writer lock. More...

int removed_
 Keeps track of whether <remove> has been called yet to avoid multiple <remove> calls, e.g., explicitly and implicitly in the destructor. This flag isn't protected by a lock, so make sure that you don't have multiple threads simultaneously calling <remove> on the same object, which is a bad idea anyway... More...


Private Methods

void operator= (const ACE_RW_Mutex &)
 ACE_RW_Mutex (const ACE_RW_Mutex &)

Detailed Description

Wrapper for readers/writer locks.

These are most useful for applications that have many more parallel readers than writers...

Definition at line 377 of file Synch.h.


Constructor & Destructor Documentation

ACE_RW_Mutex::ACE_RW_Mutex int    type = USYNC_THREAD,
const ACE_TCHAR   name = 0,
void *    arg = 0
 

Initialize a readers/writer lock.

Definition at line 860 of file Synch.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, LM_ERROR, and ACE_OS::rwlock_init.

00861   : removed_ (0)
00862 {
00863 // ACE_TRACE ("ACE_RW_Mutex::ACE_RW_Mutex");
00864   if (ACE_OS::rwlock_init (&this->lock_, type, name, arg) != 0)
00865     ACE_ERROR ((LM_ERROR,
00866                 ACE_LIB_TEXT ("%p\n"),
00867                 ACE_LIB_TEXT ("ACE_RW_Mutex::ACE_RW_Mutex")));
00868 }

ACE_RW_Mutex::~ACE_RW_Mutex void   
 

Implicitly destroy a readers/writer lock.

Definition at line 870 of file Synch.cpp.

References remove.

00871 {
00872 // ACE_TRACE ("ACE_RW_Mutex::~ACE_RW_Mutex");
00873   this->remove ();
00874 }

ACE_RW_Mutex::ACE_RW_Mutex const ACE_RW_Mutex &    [private]
 


Member Function Documentation

ACE_INLINE int ACE_RW_Mutex::acquire void   
 

Note, for interface uniformity with other synchronization wrappers we include the <acquire> method. This is implemented as a write-lock to safe...

Definition at line 44 of file Synch.i.

References ACE_OS::rw_wrlock.

00045 {
00046 // ACE_TRACE ("ACE_RW_Mutex::acquire");
00047   return ACE_OS::rw_wrlock (&this->lock_);
00048 }

ACE_INLINE int ACE_RW_Mutex::acquire_read void   
 

Acquire a read lock, but block if a writer hold the lock.

Definition at line 30 of file Synch.i.

References ACE_OS::rw_rdlock.

00031 {
00032 // ACE_TRACE ("ACE_RW_Mutex::acquire_read");
00033   return ACE_OS::rw_rdlock (&this->lock_);
00034 }

ACE_INLINE int ACE_RW_Mutex::acquire_write void   
 

Acquire a write lock, but block if any readers or a writer hold the lock.

Definition at line 37 of file Synch.i.

References ACE_OS::rw_wrlock.

00038 {
00039 // ACE_TRACE ("ACE_RW_Mutex::acquire_write");
00040   return ACE_OS::rw_wrlock (&this->lock_);
00041 }

void ACE_RW_Mutex::dump void    const
 

Dump the state of an object.

Reimplemented in ACE_RW_Thread_Mutex.

Definition at line 851 of file Synch.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, and LM_DEBUG.

Referenced by ACE_RW_Thread_Mutex::dump.

00852 {
00853 // ACE_TRACE ("ACE_RW_Mutex::dump");
00854 
00855   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00856   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00857   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00858 }

ACE_INLINE const ACE_rwlock_t & ACE_RW_Mutex::lock void    const
 

Return the underlying lock.

Definition at line 10 of file Synch.i.

References lock_.

00011 {
00012 // ACE_TRACE ("ACE_RW_Mutex::lock");
00013   return this->lock_;
00014 }

void ACE_RW_Mutex::operator= const ACE_RW_Mutex &    [private]
 

ACE_INLINE int ACE_RW_Mutex::release void   
 

Unlock a readers/writer lock.

Definition at line 79 of file Synch.i.

References ACE_OS::rw_unlock.

00080 {
00081 // ACE_TRACE ("ACE_RW_Mutex::release");
00082   return ACE_OS::rw_unlock (&this->lock_);
00083 }

ACE_INLINE int ACE_RW_Mutex::remove void   
 

Explicitly destroy a readers/writer lock. Note that only one thread should call this method since it doesn't protect against race conditions.

Definition at line 17 of file Synch.i.

References removed_, and ACE_OS::rwlock_destroy.

Referenced by ~ACE_RW_Mutex.

00018 {
00019 // ACE_TRACE ("ACE_RW_Mutex::remove");
00020   int result = 0;
00021   if (this->removed_ == 0)
00022     {
00023       this->removed_ = 1;
00024       result = ACE_OS::rwlock_destroy (&this->lock_);
00025     }
00026   return result;
00027 }

ACE_INLINE int ACE_RW_Mutex::tryacquire void   
 

Note, for interface uniformity with other synchronization wrappers we include the <tryacquire> method. This is implemented as a write-lock to be safe... Returns -1 on failure. If we "failed" because someone else already had the lock, <errno> is set to <EBUSY>.

Definition at line 72 of file Synch.i.

References tryacquire_write.

00073 {
00074 // ACE_TRACE ("ACE_RW_Mutex::tryacquire");
00075   return this->tryacquire_write ();
00076 }

ACE_INLINE int ACE_RW_Mutex::tryacquire_read void   
 

Conditionally acquire a read lock (i.e., won't block). Returns -1 on failure. If we "failed" because someone else already had the lock, <errno> is set to <EBUSY>.

Definition at line 51 of file Synch.i.

References ACE_OS::rw_tryrdlock.

00052 {
00053 // ACE_TRACE ("ACE_RW_Mutex::tryacquire_read");
00054   return ACE_OS::rw_tryrdlock (&this->lock_);
00055 }

ACE_INLINE int ACE_RW_Mutex::tryacquire_write void   
 

Conditionally acquire a write lock (i.e., won't block).

Definition at line 58 of file Synch.i.

References ACE_OS::rw_trywrlock.

Referenced by tryacquire.

00059 {
00060 // ACE_TRACE ("ACE_RW_Mutex::tryacquire_write");
00061   return ACE_OS::rw_trywrlock (&this->lock_);
00062 }

ACE_INLINE int ACE_RW_Mutex::tryacquire_write_upgrade void   
 

Conditionally upgrade a read lock to a write lock. This only works if there are no other readers present, in which case the method returns 0. Otherwise, the method returns -1 and sets <errno> to <EBUSY>. Note that the caller of this method *must* already possess this lock as a read lock (but this condition is not checked by the current implementation).

Reimplemented in ACE_RW_Thread_Mutex.

Definition at line 65 of file Synch.i.

References ACE_OS::rw_trywrlock_upgrade.

00066 {
00067 // ACE_TRACE ("ACE_RW_Mutex::tryacquire_write_upgrade");
00068   return ACE_OS::rw_trywrlock_upgrade (&this->lock_);
00069 }


Member Data Documentation

ACE_RW_Mutex::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented in ACE_RW_Thread_Mutex.

Definition at line 448 of file Synch.h.

ACE_rwlock_t ACE_RW_Mutex::lock_ [protected]
 

Readers/writer lock.

Definition at line 452 of file Synch.h.

Referenced by lock.

int ACE_RW_Mutex::removed_ [protected]
 

Keeps track of whether <remove> has been called yet to avoid multiple <remove> calls, e.g., explicitly and implicitly in the destructor. This flag isn't protected by a lock, so make sure that you don't have multiple threads simultaneously calling <remove> on the same object, which is a bad idea anyway...

Definition at line 459 of file Synch.h.

Referenced by remove.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:55:27 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002