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

ACE_Guard Class Template Reference

This data structure is meant to be used within a method or function... It performs automatic aquisition and release of a parameterized synchronization object <ACE_LOCK>. More...

#include <Synch_T.h>

Inheritance diagram for ACE_Guard:

Inheritance graph
[legend]
Collaboration diagram for ACE_Guard:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Guard (ACE_LOCK &l)
 ACE_Guard (ACE_LOCK &l, int block)
 Implicitly and automatically acquire (or try to acquire) the lock. If <block> is non-0 then <acquire> the <ACE_LOCK>, else <tryacquire> it. More...

 ACE_Guard (ACE_LOCK &l, int block, int become_owner)
 Initialise the guard without implicitly acquiring the lock. The <become_owner> parameter indicates whether the guard should release the lock implicitly on destruction. The <block> parameter is ignored and is used here to disambiguate with the preceding constructor. More...

 ~ACE_Guard (void)
 Implicitly release the lock. More...

int acquire (void)
 Explicitly acquire the lock. More...

int tryacquire (void)
 Conditionally acquire the lock (i.e., won't block). More...

int release (void)
 Explicitly release the lock, but only if it is held! More...

void disown (void)
 Relinquish ownership of the lock so that it is not released implicitly in the destructor. More...

int locked (void) const
 1 if locked, 0 if couldn't acquire the lock (errno will contain the reason for this). More...

int remove (void)
 Explicitly remove the lock. More...

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


Protected Methods

 ACE_Guard (ACE_LOCK *lock)
 Helper, meant for subclass only. More...


Protected Attributes

ACE_LOCK * lock_
 Pointer to the ACE_LOCK we're guarding. More...

int owner_
 Keeps track of whether we acquired the lock or failed. More...


Private Methods

void operator= (const ACE_Guard< ACE_LOCK > &)
 ACE_Guard (const ACE_Guard< ACE_LOCK > &)

Detailed Description

template<class ACE_LOCK>
class ACE_Guard< ACE_LOCK >

This data structure is meant to be used within a method or function... It performs automatic aquisition and release of a parameterized synchronization object <ACE_LOCK>.

The <ACE_LOCK> class given as an actual parameter must provide at the very least the <acquire>, <tryacquire>, <release>, and <remove> methods.

Definition at line 350 of file Synch_T.h.


Constructor & Destructor Documentation

template<class ACE_LOCK>
ACE_INLINE ACE_Guard< ACE_LOCK >::ACE_Guard ACE_LOCK &    l
 

Definition at line 31 of file Synch_T.i.

References acquire.

00032   : lock_ (&l),
00033     owner_ (0)
00034 {
00035   this->acquire ();
00036 }

template<class ACE_LOCK>
ACE_INLINE ACE_Guard< ACE_LOCK >::ACE_Guard ACE_LOCK &    l,
int    block
 

Implicitly and automatically acquire (or try to acquire) the lock. If <block> is non-0 then <acquire> the <ACE_LOCK>, else <tryacquire> it.

Definition at line 39 of file Synch_T.i.

References acquire, and tryacquire.

00040   : lock_ (&l),
00041     owner_ (0)
00042 {
00043   if (block)
00044     this->acquire ();
00045   else
00046     this->tryacquire ();
00047 }

template<class ACE_LOCK>
ACE_INLINE ACE_Guard< ACE_LOCK >::ACE_Guard ACE_LOCK &    l,
int    block,
int    become_owner
 

Initialise the guard without implicitly acquiring the lock. The <become_owner> parameter indicates whether the guard should release the lock implicitly on destruction. The <block> parameter is ignored and is used here to disambiguate with the preceding constructor.

Definition at line 50 of file Synch_T.i.

00051   : lock_ (&l),
00052     owner_ (become_owner == 0 ? -1 : 0)
00053 {
00054   ACE_UNUSED_ARG (block);
00055 }

template<class ACE_LOCK>
ACE_INLINE ACE_Guard< ACE_LOCK >::~ACE_Guard void   
 

Implicitly release the lock.

Definition at line 61 of file Synch_T.i.

References release.

00062 {
00063   this->release ();
00064 }

template<class ACE_LOCK>
ACE_Guard< ACE_LOCK >::ACE_Guard ACE_LOCK *    lock [inline, protected]
 

Helper, meant for subclass only.

Definition at line 404 of file Synch_T.h.

References lock_.

00404 : lock_ (lock) {}

template<class ACE_LOCK>
ACE_Guard< ACE_LOCK >::ACE_Guard const ACE_Guard< ACE_LOCK > &    [private]
 


Member Function Documentation

template<class ACE_LOCK>
ACE_INLINE int ACE_Guard< ACE_LOCK >::acquire void   
 

Explicitly acquire the lock.

Reimplemented in ACE_Write_Guard.

Definition at line 7 of file Synch_T.i.

References lock_, and owner_.

Referenced by ACE_Guard.

00008 {
00009   return this->owner_ = this->lock_->acquire ();
00010 }

template<class ACE_LOCK>
ACE_INLINE void ACE_Guard< ACE_LOCK >::disown void   
 

Relinquish ownership of the lock so that it is not released implicitly in the destructor.

Definition at line 79 of file Synch_T.i.

References owner_.

00080 {
00081   this->owner_ = -1;
00082 }

template<class ACE_LOCK>
void ACE_Guard< ACE_LOCK >::dump void    const
 

Dump the state of an object.

Reimplemented in ACE_Write_Guard.

Definition at line 40 of file Synch_T.cpp.

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

Referenced by ACE_Read_Guard::dump, and ACE_Write_Guard::dump.

00041 {
00042 // ACE_TRACE ("ACE_Guard<ACE_LOCK>::dump");
00043 
00044   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00045   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("mutex_ = %x\n"), this->lock_));
00046   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("owner_ = %d\n"), this->owner_));
00047   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00048 }

template<class ACE_LOCK>
ACE_INLINE int ACE_Guard< ACE_LOCK >::locked void    const
 

1 if locked, 0 if couldn't acquire the lock (errno will contain the reason for this).

Definition at line 67 of file Synch_T.i.

References owner_.

00068 {
00069   return this->owner_ != -1;
00070 }

template<class ACE_LOCK>
void ACE_Guard< ACE_LOCK >::operator= const ACE_Guard< ACE_LOCK > &    [private]
 

template<class ACE_LOCK>
ACE_INLINE int ACE_Guard< ACE_LOCK >::release void   
 

Explicitly release the lock, but only if it is held!

Definition at line 19 of file Synch_T.i.

References lock_, and owner_.

Referenced by ~ACE_Guard.

00020 {
00021   if (this->owner_ == -1)
00022     return -1;
00023   else
00024     {
00025       this->owner_ = -1;
00026       return this->lock_->release ();
00027     }
00028 }

template<class ACE_LOCK>
ACE_INLINE int ACE_Guard< ACE_LOCK >::remove void   
 

Explicitly remove the lock.

Definition at line 73 of file Synch_T.i.

References lock_.

00074 {
00075   return this->lock_->remove ();
00076 }

template<class ACE_LOCK>
ACE_INLINE int ACE_Guard< ACE_LOCK >::tryacquire void   
 

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

Reimplemented in ACE_Write_Guard.

Definition at line 13 of file Synch_T.i.

References lock_, and owner_.

Referenced by ACE_Guard.

00014 {
00015   return this->owner_ = this->lock_->tryacquire ();
00016 }


Member Data Documentation

template<class ACE_LOCK>
ACE_LOCK* ACE_Guard::lock_ [protected]
 

Pointer to the ACE_LOCK we're guarding.

Definition at line 407 of file Synch_T.h.

Referenced by ACE_Guard, ACE_Read_Guard::acquire, ACE_Write_Guard::acquire, acquire, ACE_Read_Guard::acquire_read, ACE_Write_Guard::acquire_write, release, remove, ACE_Read_Guard::tryacquire, ACE_Write_Guard::tryacquire, tryacquire, ACE_Read_Guard::tryacquire_read, and ACE_Write_Guard::tryacquire_write.

template<class ACE_LOCK>
int ACE_Guard::owner_ [protected]
 

Keeps track of whether we acquired the lock or failed.

Definition at line 410 of file Synch_T.h.

Referenced by ACE_Read_Guard::acquire, ACE_Write_Guard::acquire, acquire, ACE_Read_Guard::acquire_read, ACE_Write_Guard::acquire_write, disown, locked, release, ACE_Read_Guard::tryacquire, ACE_Write_Guard::tryacquire, tryacquire, ACE_Read_Guard::tryacquire_read, and ACE_Write_Guard::tryacquire_write.


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