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

Token_Manager.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Token_Manager.h
00006  *
00007  *  $Id: Token_Manager.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Tim Harrison (harrison@cs.wustl.edu)
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_TOKEN_MANAGER_H
00014 #define ACE_TOKEN_MANAGER_H
00015 #include "ace/pre.h"
00016 
00017 #include "ace/Synch.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #include "ace/Map_Manager.h"
00024 #include "ace/Local_Tokens.h"
00025 
00026 #if defined (ACE_HAS_TOKENS_LIBRARY)
00027 
00028 class ACE_Local_Mutex;
00029 class ACE_Mutex_Token;
00030 
00031 /**
00032  * @class ACE_Token_Manager
00033  *
00034  * @brief Manages all tokens in a process space.
00035  *
00036  * Factory:  Proxies use the token manager to obtain token
00037  * references.  This allows multiple proxies to reference the same
00038  * logical token.
00039  * Deadlock detection:  Tokens use the manager to check for
00040  * deadlock situations during acquires.
00041  */
00042 class ACE_Export ACE_Token_Manager : public ACE_Cleanup
00043 {
00044 
00045   //   To add a new type of token (e.g. semaphore), do the following
00046   //   steps: 1. Create a new derivation of ACE_Token.  This class
00047   //   defines the semantics of the new Token.  2.  Create a
00048   //   derivation of ACE_Token_Manager.  You will only need to
00049   //   redefine make_mutex.
00050 public:
00051   ACE_Token_Manager (void);
00052   virtual ~ACE_Token_Manager (void);
00053 
00054   /// Get the pointer to token manager singleton.
00055   static ACE_Token_Manager *instance (void);
00056 
00057   /// Set the pointer to token manager singleton.
00058   void instance (ACE_Token_Manager *);
00059 
00060   /**
00061    * The Token manager uses ACE_Token_Proxy::token_id_ to look for
00062    * an existing token.  If none is found, the Token Manager calls
00063    * ACE_Token_Proxy::create_token to create a new one.  When
00064    * finished, sets ACE_Token_Proxy::token_.  <token_name> uniquely
00065    * id's the token name.
00066    */
00067   void get_token (ACE_Token_Proxy *, const ACE_TCHAR *token_name);
00068 
00069   /**
00070    * Check whether acquire will cause deadlock or not.
00071    * returns 1 if the acquire will _not_ cause deadlock.
00072    * returns 0 if the acquire _will_ cause deadlock.
00073    * This method ignores recursive acquisition.  That is, it will not
00074    * report deadlock if the client holding the token requests the
00075    * token again.  Thus, it assumes recursive mutexes.
00076    */
00077   int check_deadlock (ACE_Token_Proxy *proxy);
00078   int check_deadlock (ACE_Tokens *token, ACE_Token_Proxy *proxy);
00079 
00080   /// Notify the token manager that a token has been released.  If as a
00081   /// result, there is no owner of the token, the token is deleted.
00082   void release_token (ACE_Tokens *&token);
00083 
00084   /**
00085    * This is to allow Tokens to perform atomic transactions.  The
00086    * typical usage is to acquire this mutex, check for a safe_acquire,
00087    * perform some queueing (if need be) and then release the lock.
00088    * This is necessary since safe_acquire is implemented in terms of
00089    * the Token queues.
00090    */
00091   ACE_TOKEN_CONST::MUTEX &mutex (void);
00092 
00093   /// Dump the state of the class.
00094   void dump (void) const;
00095 
00096   /// Turn debug mode on/off.
00097   void debug (int d);
00098 
00099 private:
00100   /// Whether to print debug messages or not.
00101   int debug_;
00102 
00103   /// pointer to singleton token manager.
00104   static ACE_Token_Manager *token_manager_;
00105 
00106   /// Return the token that the given client_id is waiting for, if any
00107   ACE_Tokens *token_waiting_for (const ACE_TCHAR *client_id);
00108 
00109   /// ACE_Mutex_Token used to lock internal data structures.
00110   ACE_TOKEN_CONST::MUTEX lock_;
00111 
00112   /// This may be changed to a template type.
00113   typedef ACE_Token_Name TOKEN_NAME;
00114 
00115   /// COLLECTION maintains a mapping from token names to ACE_Tokens*
00116   typedef ACE_Map_Manager<TOKEN_NAME, ACE_Tokens *, ACE_Null_Mutex>
00117   COLLECTION;
00118 
00119   /// Allows iterations through collection_
00120   typedef ACE_Map_Iterator<TOKEN_NAME, ACE_Tokens *, ACE_Null_Mutex>
00121   COLLECTION_ITERATOR;
00122 
00123   /// Allows iterations through collection_
00124   typedef ACE_Map_Entry<TOKEN_NAME, ACE_Tokens *>
00125   COLLECTION_ENTRY;
00126 
00127   /// COLLECTION maintains a mapping from token names to ACE_Tokens*.
00128   COLLECTION collection_;
00129 };
00130 
00131 #endif /* ACE_HAS_TOKENS_LIBRARY */
00132 
00133 #if defined (__ACE_INLINE__)
00134 #include "ace/Token_Manager.i"
00135 #endif /* __ACE_INLINE__ */
00136 
00137 #include "ace/post.h"
00138 #endif /* ACE_TOKEN_MANAGER_H */

Generated on Mon Jun 16 11:21:58 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002