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

ACE_Token_Invariant_Manager Class Reference

Token Invariants. More...

#include <Token_Invariants.h>

Inheritance diagram for ACE_Token_Invariant_Manager:

Inheritance graph
[legend]
Collaboration diagram for ACE_Token_Invariant_Manager:

Collaboration graph
[legend]
List of all members.

Public Methods

int acquired (const ACE_Token_Proxy *proxy)
 Returns 1 on success, 0 when an invariant has been violated and -1 on error. More...

void releasing (const ACE_Token_Proxy *proxy)
 Updates internal database. More...

int mutex_acquired (const ACE_TCHAR *token_name)
 Returns 1 on success, 0 when an invariant has been violated and -1 on error. More...

void mutex_releasing (const ACE_TCHAR *token_name)
 Updates internal database. More...

int reader_acquired (const ACE_TCHAR *token_name)
 Returns 1 on success, 0 when an invariant has been violated and -1 on error. More...

int writer_acquired (const ACE_TCHAR *token_name)
 Returns 1 on success, 0 when an invariant has been violated and -1 on error. More...

void rwlock_releasing (const ACE_TCHAR *token_name)
 Updates internal database. More...

void dump (void) const
 Dump the state of the class. More...

 ACE_Token_Invariant_Manager (void)
 Prevent non-singleton construction. More...

virtual ~ACE_Token_Invariant_Manager (void)
 Destruction. More...


Static Public Methods

ACE_Token_Invariant_Manager * instance (void)
 Singleton access point. More...


Protected Types

typedef ACE_Token_Name TOKEN_NAME
 This may be changed to a template type. More...

typedef ACE_Map_Manager< TOKEN_NAME,
ACE_Mutex_Invariants *, ACE_Null_Mutex
MUTEX_COLLECTION
 COLLECTION maintains a mapping from token names to mutexes. More...

typedef ACE_Map_Iterator<
TOKEN_NAME, ACE_Mutex_Invariants *,
ACE_Null_Mutex
MUTEX_COLLECTION_ITERATOR
 Allows iterations through collection. More...

typedef ACE_Map_Entry< TOKEN_NAME,
ACE_Mutex_Invariants * > 
MUTEX_COLLECTION_ENTRY
 Allows iterations through collection. More...

typedef ACE_Map_Manager< TOKEN_NAME,
ACE_RWLock_Invariants *,
ACE_Null_Mutex
RWLOCK_COLLECTION
 COLLECTION maintains a mapping from token names to mutexes. More...

typedef ACE_Map_Iterator<
TOKEN_NAME, ACE_RWLock_Invariants *,
ACE_Null_Mutex
RWLOCK_COLLECTION_ITERATOR
 Allows iterations through collection. More...

typedef ACE_Map_Entry< TOKEN_NAME,
ACE_RWLock_Invariants * > 
RWLOCK_COLLECTION_ENTRY
 Allows iterations through collection. More...


Protected Methods

int get_mutex (const ACE_TCHAR *token_name, ACE_Mutex_Invariants *&inv)
 Return or create. More...

int get_rwlock (const ACE_TCHAR *token_name, ACE_RWLock_Invariants *&inv)
 Return or create. More...


Protected Attributes

ACE_TOKEN_CONST::MUTEX lock_
 ACE_Mutex_Token used to lock internal data structures. More...

MUTEX_COLLECTION mutex_collection_
 MUTEX_COLLECTION maintains a mapping from token names to mutexes. More...

RWLOCK_COLLECTION rwlock_collection_
 MUTEX_COLLECTION maintains a mapping from token names to mutexes. More...


Static Protected Attributes

ACE_Token_Invariant_Manager * instance_ = 0
 Singleton pointer. More...


Detailed Description

Token Invariants.

The Token Invariant Manager allows applications to test that invariants are always satisfied. Currently, Token_Invariants can test mutexes and readers/writer locks. Does not test recursive acquisition. Note that this class does not ever clean its database. Until destroyed, it's size will forever increase.

Definition at line 127 of file Token_Invariants.h.


Member Typedef Documentation

typedef ACE_Map_Manager<TOKEN_NAME, ACE_Mutex_Invariants *, ACE_Null_Mutex> ACE_Token_Invariant_Manager::MUTEX_COLLECTION [protected]
 

COLLECTION maintains a mapping from token names to mutexes.

Definition at line 193 of file Token_Invariants.h.

typedef ACE_Map_Entry<TOKEN_NAME, ACE_Mutex_Invariants *> ACE_Token_Invariant_Manager::MUTEX_COLLECTION_ENTRY [protected]
 

Allows iterations through collection.

Definition at line 201 of file Token_Invariants.h.

typedef ACE_Map_Iterator<TOKEN_NAME, ACE_Mutex_Invariants *, ACE_Null_Mutex> ACE_Token_Invariant_Manager::MUTEX_COLLECTION_ITERATOR [protected]
 

Allows iterations through collection.

Definition at line 197 of file Token_Invariants.h.

typedef ACE_Map_Manager<TOKEN_NAME, ACE_RWLock_Invariants *, ACE_Null_Mutex> ACE_Token_Invariant_Manager::RWLOCK_COLLECTION [protected]
 

COLLECTION maintains a mapping from token names to mutexes.

Definition at line 208 of file Token_Invariants.h.

typedef ACE_Map_Entry<TOKEN_NAME, ACE_RWLock_Invariants *> ACE_Token_Invariant_Manager::RWLOCK_COLLECTION_ENTRY [protected]
 

Allows iterations through collection.

Definition at line 216 of file Token_Invariants.h.

typedef ACE_Map_Iterator<TOKEN_NAME, ACE_RWLock_Invariants *, ACE_Null_Mutex> ACE_Token_Invariant_Manager::RWLOCK_COLLECTION_ITERATOR [protected]
 

Allows iterations through collection.

Definition at line 212 of file Token_Invariants.h.

typedef ACE_Token_Name ACE_Token_Invariant_Manager::TOKEN_NAME [protected]
 

This may be changed to a template type.

Definition at line 189 of file Token_Invariants.h.


Constructor & Destructor Documentation

ACE_Token_Invariant_Manager::ACE_Token_Invariant_Manager void   
 

Prevent non-singleton construction.

Definition at line 39 of file Token_Invariants.cpp.

References ACE_TRACE.

00040 {
00041   ACE_TRACE ("ACE_Token_Invariant_Manager::ACE_Token_Invariant_Manager");
00042 }

ACE_Token_Invariant_Manager::~ACE_Token_Invariant_Manager void    [virtual]
 

Destruction.

Definition at line 204 of file Token_Invariants.cpp.

References ACE_TRACE, ACE_Map_Iterator::advance, ACE_Map_Entry< TOKEN_NAME, ACE_RWLock_Invariants * >::int_id_, ACE_Map_Entry< TOKEN_NAME, ACE_Mutex_Invariants * >::int_id_, mutex_collection_, ACE_Map_Iterator_Base::next, and rwlock_collection_.

00205 {
00206   ACE_TRACE ("ACE_Token_Invariant_Manager::~ACE_Token_Invariant_Manager");
00207   MUTEX_COLLECTION_ITERATOR iterator (mutex_collection_);
00208 
00209   for (MUTEX_COLLECTION_ENTRY *temp = 0;
00210        iterator.next (temp) != 0;
00211        iterator.advance ())
00212     delete temp->int_id_;
00213 
00214   RWLOCK_COLLECTION_ITERATOR iterator2 (rwlock_collection_);
00215 
00216   for (RWLOCK_COLLECTION_ENTRY *temp2 = 0;
00217        iterator2.next (temp2) != 0;
00218        iterator2.advance ())
00219     delete temp2->int_id_;
00220 }


Member Function Documentation

int ACE_Token_Invariant_Manager::acquired const ACE_Token_Proxy   proxy
 

Returns 1 on success, 0 when an invariant has been violated and -1 on error.

Definition at line 59 of file Token_Invariants.cpp.

References ACE_TRACE, ACE_Tokens::MUTEX, mutex_acquired, ACE_Token_Proxy::name, ACE_RW_Token::READER, reader_acquired, ACE_Token_Proxy::token_, ACE_Token_Proxy::type, ACE_Tokens::type, and writer_acquired.

00060 {
00061   ACE_TRACE ("ACE_Token_Invariant_Manager::acquired");
00062 
00063   // Reach into the proxy to find the token type.
00064   if (proxy->token_->type () == ACE_Tokens::MUTEX)
00065     return this->mutex_acquired (proxy->name ());
00066   else // ACE_Tokens::RWLOCK.
00067     {
00068       if (proxy->type () == ACE_RW_Token::READER)
00069         return this->reader_acquired (proxy->name ());
00070       else // ACE_RW_Token::WRITER.
00071         return this->writer_acquired (proxy->name ());
00072     }
00073 }

void ACE_Token_Invariant_Manager::dump void    const
 

Dump the state of the class.

Definition at line 138 of file Token_Invariants.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, ACE_Map_Manager< TOKEN_NAME, ACE_RWLock_Invariants *, ACE_Null_Mutex >::dump, ACE_Map_Manager< TOKEN_NAME, ACE_Mutex_Invariants *, ACE_Null_Mutex >::dump, LM_DEBUG, mutex_collection_, and rwlock_collection_.

00139 {
00140   ACE_TRACE ("ACE_Token_Invariant_Manager::dump");
00141   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00142   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("mutex_collection_:\n")));
00143   mutex_collection_.dump ();
00144   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("rwlock_collection_:\n")));
00145   rwlock_collection_.dump ();
00146   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00147 }

int ACE_Token_Invariant_Manager::get_mutex const ACE_TCHAR   token_name,
ACE_Mutex_Invariants *&    inv
[protected]
 

Return or create.

Definition at line 151 of file Token_Invariants.cpp.

References ACE_NEW_RETURN, ACE_TCHAR, ACE_TRACE, ACE_Map_Manager< TOKEN_NAME, ACE_Mutex_Invariants *, ACE_Null_Mutex >::bind, ACE_Map_Manager< TOKEN_NAME, ACE_Mutex_Invariants *, ACE_Null_Mutex >::find, and mutex_collection_.

Referenced by mutex_acquired, and mutex_releasing.

00153 {
00154   ACE_TRACE ("ACE_Token_Invariant_Manager::get_mutex");
00155   TOKEN_NAME name (token_name);
00156   if (mutex_collection_.find (name, inv) == -1)
00157     // We did not find one in the collection.
00158     {
00159       ACE_Mutex_Invariants *new_invariant;
00160 
00161       ACE_NEW_RETURN (new_invariant,
00162                       ACE_Mutex_Invariants,
00163                       -1);
00164       if (mutex_collection_.bind (name, new_invariant) == -1)
00165         {
00166           delete new_invariant;
00167           return -1;
00168         }
00169 
00170       if (mutex_collection_.find (name, inv) == -1)
00171         // We did not find one in the collection.
00172         return -1;
00173     }
00174 
00175   return 0;
00176 }

int ACE_Token_Invariant_Manager::get_rwlock const ACE_TCHAR   token_name,
ACE_RWLock_Invariants *&    inv
[protected]
 

Return or create.

Definition at line 179 of file Token_Invariants.cpp.

References ACE_NEW_RETURN, ACE_TCHAR, ACE_TRACE, ACE_Map_Manager< TOKEN_NAME, ACE_RWLock_Invariants *, ACE_Null_Mutex >::bind, ACE_Map_Manager< TOKEN_NAME, ACE_RWLock_Invariants *, ACE_Null_Mutex >::find, and rwlock_collection_.

Referenced by reader_acquired, rwlock_releasing, and writer_acquired.

00181 {
00182   ACE_TRACE ("ACE_Token_Invariant_Manager::get_rwlock");
00183   TOKEN_NAME name (token_name);
00184   if (rwlock_collection_.find (name, inv) == -1)
00185     // We did not find one in the collection.
00186     {
00187       ACE_RWLock_Invariants *new_invariant;
00188 
00189       ACE_NEW_RETURN (new_invariant,
00190                       ACE_RWLock_Invariants,
00191                       -1);
00192       if (rwlock_collection_.bind (name, new_invariant) == -1)
00193         return -1;
00194 
00195       if (rwlock_collection_.find (name, inv) == -1)
00196         // We did not find one in the collection.
00197         return -1;
00198     }
00199 
00200   return 0;
00201 }

ACE_Token_Invariant_Manager * ACE_Token_Invariant_Manager::instance void    [static]
 

Singleton access point.

Definition at line 14 of file Token_Invariants.cpp.

References ACE_GUARD_RETURN, ACE_MT, ACE_NEW_RETURN, ACE_TRACE, ACE_Object_Manager::at_exit, instance_, and ACE_TOKEN_CONST::MUTEX.

00015 {
00016   ACE_TRACE ("ACE_Token_Invariant_Manager::instance");
00017 
00018   // Perform the Double-Check pattern...
00019   if (instance_ == 0)
00020     {
00021       ACE_MT (ACE_TOKEN_CONST::MUTEX *lock =
00022         ACE_Managed_Object<ACE_TOKEN_CONST::MUTEX>::get_preallocated_object
00023           (ACE_Object_Manager::ACE_TOKEN_INVARIANTS_CREATION_LOCK);
00024         ACE_GUARD_RETURN (ACE_TOKEN_CONST::MUTEX, ace_mon, *lock, 0));
00025 
00026       if (instance_ == 0)
00027         {
00028           ACE_NEW_RETURN (instance_,
00029                           ACE_Token_Invariant_Manager,
00030                           0);
00031           // Register for destruction with ACE_Object_Manager.
00032           ACE_Object_Manager::at_exit (instance_);
00033         }
00034     }
00035 
00036   return instance_;
00037 }

int ACE_Token_Invariant_Manager::mutex_acquired const ACE_TCHAR   token_name
 

Returns 1 on success, 0 when an invariant has been violated and -1 on error.

Definition at line 45 of file Token_Invariants.cpp.

References ACE_GUARD_RETURN, ACE_TCHAR, ACE_TRACE, ACE_Mutex_Invariants::acquired, get_mutex, ACE_Null_Mutex::lock_, and ACE_TOKEN_CONST::MUTEX.

Referenced by acquired.

00046 {
00047   ACE_TRACE ("ACE_Token_Invariant_Manager::mutex_acquired");
00048 
00049   ACE_GUARD_RETURN (ACE_TOKEN_CONST::MUTEX, ace_mon, this->lock_, -1);
00050 
00051   ACE_Mutex_Invariants *inv = 0;
00052   if (this->get_mutex (token_name, inv) == -1)
00053     return -1;
00054 
00055   return inv->acquired ();
00056 }

void ACE_Token_Invariant_Manager::mutex_releasing const ACE_TCHAR   token_name
 

Updates internal database.

Definition at line 88 of file Token_Invariants.cpp.

References ACE_GUARD, ACE_TCHAR, ACE_TRACE, get_mutex, ACE_Null_Mutex::lock_, ACE_TOKEN_CONST::MUTEX, and ACE_Mutex_Invariants::releasing.

Referenced by releasing.

00089 {
00090   ACE_TRACE ("ACE_Token_Invariant_Manager::mutex_releasing");
00091   ACE_GUARD (ACE_TOKEN_CONST::MUTEX, ace_mon, this->lock_);
00092 
00093   ACE_Mutex_Invariants *inv = 0;
00094   if (this->get_mutex (token_name, inv) == 0)
00095     inv->releasing ();
00096 }

int ACE_Token_Invariant_Manager::reader_acquired const ACE_TCHAR   token_name
 

Returns 1 on success, 0 when an invariant has been violated and -1 on error.

Definition at line 99 of file Token_Invariants.cpp.

References ACE_GUARD_RETURN, ACE_TCHAR, ACE_TRACE, get_rwlock, ACE_Null_Mutex::lock_, ACE_TOKEN_CONST::MUTEX, and ACE_RWLock_Invariants::reader_acquired.

Referenced by acquired.

00100 {
00101   ACE_TRACE ("ACE_Token_Invariant_Manager::reader_acquired");
00102   ACE_GUARD_RETURN (ACE_TOKEN_CONST::MUTEX, ace_mon, this->lock_, -1);
00103 
00104   ACE_RWLock_Invariants *inv = 0;
00105   if (this->get_rwlock (token_name, inv) == -1)
00106     return -1;
00107 
00108   return inv->reader_acquired ();
00109 }

void ACE_Token_Invariant_Manager::releasing const ACE_Token_Proxy   proxy
 

Updates internal database.

Definition at line 76 of file Token_Invariants.cpp.

References ACE_TRACE, ACE_Tokens::MUTEX, mutex_releasing, ACE_Token_Proxy::name, rwlock_releasing, ACE_Token_Proxy::token_, and ACE_Tokens::type.

00077 {
00078   ACE_TRACE ("ACE_Token_Invariant_Manager::releasing");
00079 
00080   // Reach into the proxy to find the token type.
00081   if (proxy->token_->type () == ACE_Tokens::MUTEX)
00082     this->mutex_releasing (proxy->name ());
00083   else // ACE_Tokens::RWLOCK.
00084     this->rwlock_releasing (proxy->name ());
00085 }

void ACE_Token_Invariant_Manager::rwlock_releasing const ACE_TCHAR   token_name
 

Updates internal database.

Definition at line 126 of file Token_Invariants.cpp.

References ACE_GUARD, ACE_TCHAR, ACE_TRACE, get_rwlock, ACE_Null_Mutex::lock_, ACE_TOKEN_CONST::MUTEX, and ACE_RWLock_Invariants::releasing.

Referenced by releasing.

00127 {
00128   ACE_TRACE ("ACE_Token_Invariant_Manager::rwlock_releasing");
00129 
00130   ACE_GUARD (ACE_TOKEN_CONST::MUTEX, ace_mon, this->lock_);
00131 
00132   ACE_RWLock_Invariants *inv = 0;
00133   if (this->get_rwlock (token_name, inv) == 0)
00134     inv->releasing ();
00135 }

int ACE_Token_Invariant_Manager::writer_acquired const ACE_TCHAR   token_name
 

Returns 1 on success, 0 when an invariant has been violated and -1 on error.

Definition at line 112 of file Token_Invariants.cpp.

References ACE_GUARD_RETURN, ACE_TCHAR, ACE_TRACE, get_rwlock, ACE_Null_Mutex::lock_, ACE_TOKEN_CONST::MUTEX, and ACE_RWLock_Invariants::writer_acquired.

Referenced by acquired.

00113 {
00114   ACE_TRACE ("ACE_Token_Invariant_Manager::writer_acquired");
00115 
00116   ACE_GUARD_RETURN (ACE_TOKEN_CONST::MUTEX, ace_mon, this->lock_, -1);
00117 
00118   ACE_RWLock_Invariants *inv = 0;
00119   if (this->get_rwlock (token_name, inv) == -1)
00120     return -1;
00121 
00122   return inv->writer_acquired ();
00123 }


Member Data Documentation

ACE_Token_Invariant_Manager * ACE_Token_Invariant_Manager::instance_ = 0 [static, protected]
 

Singleton pointer.

Definition at line 11 of file Token_Invariants.cpp.

Referenced by instance.

ACE_TOKEN_CONST::MUTEX ACE_Token_Invariant_Manager::lock_ [protected]
 

ACE_Mutex_Token used to lock internal data structures.

Definition at line 186 of file Token_Invariants.h.

MUTEX_COLLECTION ACE_Token_Invariant_Manager::mutex_collection_ [protected]
 

MUTEX_COLLECTION maintains a mapping from token names to mutexes.

Definition at line 204 of file Token_Invariants.h.

Referenced by dump, get_mutex, and ~ACE_Token_Invariant_Manager.

RWLOCK_COLLECTION ACE_Token_Invariant_Manager::rwlock_collection_ [protected]
 

MUTEX_COLLECTION maintains a mapping from token names to mutexes.

Definition at line 219 of file Token_Invariants.h.

Referenced by dump, get_rwlock, and ~ACE_Token_Invariant_Manager.


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