ACE  6.0.6
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
ACE_Guard Class Reference

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

#include <Guard_T.h>

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

This data structure is meant to be used within a method or function... It performs automatic acquisition 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.

Warning:
A successfully constructed ACE_Guard does NOT mean that the lock was acquired! It is the caller's responsibility, after constructing an ACE_Guard, to check whether the lock was successfully acquired. Code like this is dangerous: { ACE_Guard<ACE_Lock> g(lock); ... perform critical operation requiring lock to be held ... } Instead, one must do something like this: { ACE_Guard<ACE_Lock> g(lock); if (! g.locked()) { ... handle error ... } else { ... perform critical operation requiring lock to be held ... } } The ACE_GUARD_RETURN() and ACE_GUARD_REACTION() macros are designed to to help with this.

Constructor & Destructor Documentation

ACE_Guard::ACE_Guard ( ACE_LOCK &  l)
ACE_Guard::ACE_Guard ( ACE_LOCK &  l,
bool  block 
)

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

ACE_Guard::ACE_Guard ( ACE_LOCK &  l,
bool  block,
int  become_owner 
)

Initialize 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.

ACE_Guard::~ACE_Guard ( void  )

Implicitly release the lock.

ACE_Guard::ACE_Guard ( ACE_LOCK *  lock) [inline, protected]

Helper, meant for subclass only.

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

Member Function Documentation

int ACE_Guard::acquire ( void  )

Explicitly acquire the lock.

Reimplemented in ACE_Read_Guard, and ACE_Write_Guard.

void ACE_Guard::disown ( void  )

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

void ACE_Guard::dump ( void  ) const

Dump the state of an object.

Reimplemented in ACE_Read_Guard, and ACE_Write_Guard.

bool ACE_Guard::locked ( void  ) const

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

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

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

int ACE_Guard::remove ( void  )

Explicitly remove the lock.

int ACE_Guard::tryacquire ( void  )

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

Reimplemented in ACE_Read_Guard, and ACE_Write_Guard.


Member Data Documentation

ACE_LOCK* ACE_Guard::lock_ [protected]

Pointer to the ACE_LOCK we're guarding.

int ACE_Guard::owner_ [protected]

Keeps track of whether we acquired the lock or failed.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines