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

ACE_Lock_Adapter Class Template Reference

This is an adapter that allows applications to transparently combine the <ACE_Lock> abstract base class (which contains pure virtual methods) with any of the other concrete ACE synchronization classes (e.g., <ACE_Mutex>, <ACE_Semaphore>, <ACE_RW_Mutex>, etc.). More...

#include <Synch_T.h>

Inheritance diagram for ACE_Lock_Adapter:

Inheritance graph
[legend]
Collaboration diagram for ACE_Lock_Adapter:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_LOCKING_MECHANISM ACE_LOCK

Public Methods

 ACE_Lock_Adapter (ACE_LOCKING_MECHANISM &lock)
 Constructor. All locking requests will be forwarded to <lock>. More...

 ACE_Lock_Adapter (void)
 Constructor. Since no lock is provided by the user, one will be created internally. More...

virtual ~ACE_Lock_Adapter (void)
 Destructor. If <lock_> was not passed in by the user, it will be deleted. More...

virtual int acquire (void)
 Block the thread until the lock is acquired. More...

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

virtual int release (void)
 Release the lock. More...

virtual int acquire_read (void)
virtual int acquire_write (void)
virtual int tryacquire_read (void)
 Conditionally acquire a read lock. If the locking mechanism doesn't support read locks then this just calls <acquire>. More...

virtual int tryacquire_write (void)
 Conditionally acquire a write lock. If the locking mechanism doesn't support read locks then this just calls <acquire>. More...

virtual int tryacquire_write_upgrade (void)
virtual int remove (void)
 Explicitly destroy the lock. More...


Private Attributes

ACE_LOCKING_MECHANISM * lock_
 The concrete locking mechanism that all the methods delegate to. More...

int delete_lock_
 This flag keep track of whether we are responsible for deleting the lock. More...


Detailed Description

template<class ACE_LOCKING_MECHANISM>
class ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >

This is an adapter that allows applications to transparently combine the <ACE_Lock> abstract base class (which contains pure virtual methods) with any of the other concrete ACE synchronization classes (e.g., <ACE_Mutex>, <ACE_Semaphore>, <ACE_RW_Mutex>, etc.).

This class uses a form of the Adapter pattern.

Definition at line 37 of file Synch_T.h.


Member Typedef Documentation

template<class ACE_LOCKING_MECHANISM>
typedef ACE_LOCKING_MECHANISM ACE_Lock_Adapter::ACE_LOCK
 

Definition at line 40 of file Synch_T.h.


Constructor & Destructor Documentation

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::ACE_Lock_Adapter ACE_LOCKING_MECHANISM &    lock
 

Constructor. All locking requests will be forwarded to <lock>.

Definition at line 169 of file Synch_T.i.

00170   : lock_ (&lock),
00171     delete_lock_ (0)
00172 {
00173 }

template<class ACE_LOCKING_MECHANISM>
ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::ACE_Lock_Adapter void   
 

Constructor. Since no lock is provided by the user, one will be created internally.

Definition at line 24 of file Synch_T.cpp.

References ACE_NEW.

00025   : lock_ (0),
00026     delete_lock_ (1)
00027 {
00028   ACE_NEW (this->lock_,
00029            ACE_LOCKING_MECHANISM);
00030 }

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::~ACE_Lock_Adapter void    [virtual]
 

Destructor. If <lock_> was not passed in by the user, it will be deleted.

Definition at line 176 of file Synch_T.i.

References delete_lock_, and lock_.

00177 {
00178   if (this->delete_lock_)
00179     delete this->lock_;
00180 }


Member Function Documentation

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE int ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::acquire void    [virtual]
 

Block the thread until the lock is acquired.

Implements ACE_Lock.

Definition at line 191 of file Synch_T.i.

References lock_.

00192 {
00193   return this->lock_->acquire ();
00194 }

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE int ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::acquire_read void    [virtual]
 

Block until the thread acquires a read lock. If the locking mechanism doesn't support read locks then this just calls <acquire>.

Implements ACE_Lock.

Definition at line 217 of file Synch_T.i.

References lock_.

00218 {
00219   return this->lock_->acquire_read ();
00220 }

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE int ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::acquire_write void    [virtual]
 

Block until the thread acquires a write lock. If the locking mechanism doesn't support read locks then this just calls <acquire>.

Implements ACE_Lock.

Definition at line 227 of file Synch_T.i.

References lock_.

00228 {
00229   return this->lock_->acquire_write ();
00230 }

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE int ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::release void    [virtual]
 

Release the lock.

Implements ACE_Lock.

Definition at line 207 of file Synch_T.i.

References lock_.

00208 {
00209   return this->lock_->release ();
00210 }

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE int ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::remove void    [virtual]
 

Explicitly destroy the lock.

Implements ACE_Lock.

Definition at line 184 of file Synch_T.i.

References lock_.

00185 {
00186   return this->lock_->remove ();
00187 }

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE int ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::tryacquire void    [virtual]
 

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

Implements ACE_Lock.

Definition at line 199 of file Synch_T.i.

References lock_.

00200 {
00201   return this->lock_->tryacquire ();
00202 }

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE int ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::tryacquire_read void    [virtual]
 

Conditionally acquire a read lock. If the locking mechanism doesn't support read locks then this just calls <acquire>.

Implements ACE_Lock.

Definition at line 236 of file Synch_T.i.

References lock_.

00237 {
00238   return this->lock_->tryacquire_read ();
00239 }

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE int ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::tryacquire_write void    [virtual]
 

Conditionally acquire a write lock. If the locking mechanism doesn't support read locks then this just calls <acquire>.

Implements ACE_Lock.

Definition at line 245 of file Synch_T.i.

References lock_.

00246 {
00247   return this->lock_->tryacquire_write ();
00248 }

template<class ACE_LOCKING_MECHANISM>
ACE_INLINE int ACE_Lock_Adapter< ACE_LOCKING_MECHANISM >::tryacquire_write_upgrade void    [virtual]
 

Conditionally try to upgrade a lock held for read to a write lock. If the locking mechanism doesn't support read locks then this just calls <acquire>. Returns 0 on success, -1 on failure.

Implements ACE_Lock.

Definition at line 255 of file Synch_T.i.

References lock_.

00256 {
00257   return this->lock_->tryacquire_write_upgrade ();
00258 }


Member Data Documentation

template<class ACE_LOCKING_MECHANISM>
int ACE_Lock_Adapter::delete_lock_ [private]
 

This flag keep track of whether we are responsible for deleting the lock.

Definition at line 103 of file Synch_T.h.

Referenced by ~ACE_Lock_Adapter.

template<class ACE_LOCKING_MECHANISM>
ACE_LOCKING_MECHANISM* ACE_Lock_Adapter::lock_ [private]
 

The concrete locking mechanism that all the methods delegate to.

Definition at line 99 of file Synch_T.h.

Referenced by acquire, acquire_read, acquire_write, release, remove, tryacquire, tryacquire_read, tryacquire_write, tryacquire_write_upgrade, and ~ACE_Lock_Adapter.


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