ACE_Guard< ACE_LOCK > 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 . More...

#include <Guard_T.h>

Inheritance diagram for ACE_Guard< ACE_LOCK >:

Inheritance graph
[legend]
Collaboration diagram for ACE_Guard< ACE_LOCK >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Guard (ACE_LOCK &l)
 ACE_Guard (ACE_LOCK &l, int block)
 ACE_Guard (ACE_LOCK &l, int block, int become_owner)
 ~ACE_Guard (void)
 Implicitly release the lock.

int acquire (void)
 Explicitly acquire the lock.

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

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

void disown (void)
int locked (void) const
int remove (void)
 Explicitly remove the lock.

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


Protected Member Functions

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


Protected Attributes

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

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


Private Member Functions

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 .

The class given as an actual parameter must provide at the very least the , , , and methods.

Definition at line 42 of file Guard_T.h.


Constructor & Destructor Documentation

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

Definition at line 34 of file Guard_T.inl.

References ACE_Guard< ACE_LOCK >::acquire().

00035   : lock_ (&l),
00036     owner_ (0)
00037 {
00038   this->acquire ();
00039 }

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 the , else it.

Definition at line 42 of file Guard_T.inl.

References ACE_Guard< ACE_LOCK >::acquire(), and ACE_Guard< ACE_LOCK >::tryacquire().

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

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 parameter indicates whether the guard should release the lock implicitly on destruction. The parameter is ignored and is used here to disambiguate with the preceding constructor.

Definition at line 53 of file Guard_T.inl.

00054   : lock_ (&l),
00055     owner_ (become_owner == 0 ? -1 : 0)
00056 {
00057   ACE_UNUSED_ARG (block);
00058 }

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

Implicitly release the lock.

Definition at line 64 of file Guard_T.inl.

References ACE_Guard< ACE_LOCK >::release().

00065 {
00066   this->release ();
00067 }

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

Helper, meant for subclass only.

Definition at line 96 of file Guard_T.h.

00096 : 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_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_Guard< ACE_LOCK >::acquire void   ) 
 

Explicitly acquire the lock.

Reimplemented in ACE_Write_Guard< ACE_LOCK >, and ACE_Read_Guard< ACE_LOCK >.

Definition at line 10 of file Guard_T.inl.

Referenced by ACE_Guard< ACE_LOCK >::ACE_Guard().

00011 {
00012   return this->owner_ = this->lock_->acquire ();
00013 }

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 82 of file Guard_T.inl.

00083 {
00084   this->owner_ = -1;
00085 }

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

Dump the state of an object.

Reimplemented in ACE_Write_Guard< ACE_LOCK >, and ACE_Read_Guard< ACE_LOCK >.

Definition at line 27 of file Guard_T.cpp.

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

Referenced by ACE_Read_Guard< ACE_LOCK >::dump(), and ACE_Write_Guard< ACE_LOCK >::dump().

00028 {
00029 #if defined (ACE_HAS_DUMP)
00030 // ACE_TRACE ("ACE_Guard<ACE_LOCK>::dump");
00031 
00032   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00033   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("mutex_ = %x\n"), this->lock_));
00034   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("owner_ = %d\n"), this->owner_));
00035   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00036 #endif /* ACE_HAS_DUMP */
00037 }

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 70 of file Guard_T.inl.

00071 {
00072   return this->owner_ != -1;
00073 }

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 22 of file Guard_T.inl.

Referenced by ACE_Guard< ACE_LOCK >::~ACE_Guard().

00023 {
00024   if (this->owner_ == -1)
00025     return -1;
00026   else
00027     {
00028       this->owner_ = -1;
00029       return this->lock_->release ();
00030     }
00031 }

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

Explicitly remove the lock.

Definition at line 76 of file Guard_T.inl.

00077 {
00078   return this->lock_->remove ();
00079 }

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< ACE_LOCK >, and ACE_Read_Guard< ACE_LOCK >.

Definition at line 16 of file Guard_T.inl.

Referenced by ACE_Guard< ACE_LOCK >::ACE_Guard().

00017 {
00018   return this->owner_ = this->lock_->tryacquire ();
00019 }


Member Data Documentation

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

Pointer to the ACE_LOCK we're guarding.

Definition at line 99 of file Guard_T.h.

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

Keeps track of whether we acquired the lock or failed.

Definition at line 102 of file Guard_T.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:22:39 2006 for ACE by doxygen 1.3.6