Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions

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

#include <Guard_T.h>

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

List of all members.

Public Member Functions

 ACE_Guard (ACE_LOCK &l)
 ACE_Guard (ACE_LOCK &l, bool block)
 ACE_Guard (ACE_LOCK &l, bool 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)
bool 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 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 42 of file Guard_T.h.


Constructor & Destructor Documentation

template<class ACE_LOCK >
ACE_Guard< ACE_LOCK >::ACE_Guard ( ACE_LOCK &  l  )  [inline]

Definition at line 34 of file Guard_T.inl.

  : lock_ (&l),
    owner_ (0)
{
  this->acquire ();
}

template<class ACE_LOCK >
ACE_Guard< ACE_LOCK >::ACE_Guard ( ACE_LOCK &  l,
bool  block 
) [inline]

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

  : lock_ (&l),
    owner_ (0)
{
  if (block)
    this->acquire ();
  else
    this->tryacquire ();
}

template<class ACE_LOCK >
ACE_Guard< ACE_LOCK >::ACE_Guard ( ACE_LOCK &  l,
bool  block,
int  become_owner 
) [inline]

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

  : lock_ (&l),
    owner_ (become_owner == 0 ? -1 : 0)
{
}

template<class ACE_LOCK >
ACE_Guard< ACE_LOCK >::~ACE_Guard ( void   )  [inline]

Implicitly release the lock.

Definition at line 63 of file Guard_T.inl.

{
  this->release ();
}

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.

: lock_ (lock), owner_ (0) {}

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

Member Function Documentation

template<class ACE_LOCK >
int ACE_Guard< ACE_LOCK >::acquire ( void   )  [inline]

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.

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

template<class ACE_LOCK >
void ACE_Guard< ACE_LOCK >::disown ( void   )  [inline]

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

Definition at line 81 of file Guard_T.inl.

{
  this->owner_ = -1;
}

template<class ACE_LOCK >
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.

{
#if defined (ACE_HAS_DUMP)
// ACE_TRACE ("ACE_Guard<ACE_LOCK>::dump");

  ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("mutex_ = %x\n"), this->lock_));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("owner_ = %d\n"), this->owner_));
  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP, this));
#endif /* ACE_HAS_DUMP */
}

template<class ACE_LOCK >
bool ACE_Guard< ACE_LOCK >::locked ( void   )  const [inline]

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

Definition at line 69 of file Guard_T.inl.

{
  return this->owner_ != -1;
}

template<class ACE_LOCK>
void ACE_Guard< ACE_LOCK >::operator= ( const ACE_Guard< ACE_LOCK > &   )  [private]
template<class ACE_LOCK >
int ACE_Guard< ACE_LOCK >::release ( void   )  [inline]

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

Definition at line 22 of file Guard_T.inl.

{
  if (this->owner_ == -1)
    return -1;
  else
    {
      this->owner_ = -1;
      return this->lock_->release ();
    }
}

template<class ACE_LOCK >
int ACE_Guard< ACE_LOCK >::remove ( void   )  [inline]

Explicitly remove the lock.

Definition at line 75 of file Guard_T.inl.

{
  return this->lock_->remove ();
}

template<class ACE_LOCK >
int ACE_Guard< ACE_LOCK >::tryacquire ( void   )  [inline]

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.

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


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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines