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

Based_Pointer_Repository.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: Based_Pointer_Repository.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:20 chad Exp $
00003 
00004 #include "ace/Map_Manager.h"
00005 #include "ace/Based_Pointer_Repository.h"
00006 
00007 /**
00008  * @class ACE_Based_Pointer_Repository_Rep
00009  *
00010  * @brief Implementation for the <ACE_Based_Pointer_Repository>.
00011  *
00012  * Every memory pool in ACE binds it's mapping base address and
00013  * the mapped size to this repository every time it maps/remaps a
00014  * new chunk of memory successfully.
00015  */
00016 class ACE_Based_Pointer_Repository_Rep
00017 {
00018 public:
00019   // Useful typedefs.
00020   typedef ACE_Map_Manager <void *, size_t, ACE_Null_Mutex> MAP_MANAGER;
00021   typedef ACE_Map_Iterator < void *, size_t, ACE_Null_Mutex> MAP_ITERATOR;
00022   typedef ACE_Map_Entry <void *, size_t> MAP_ENTRY;
00023 
00024   /// Keeps track of the mapping between addresses and their associated
00025   /// values.
00026   MAP_MANAGER addr_map_;
00027 
00028   /// Synchronize concurrent access to the map.
00029   ACE_SYNCH_MUTEX lock_;
00030 };
00031 
00032 ACE_Based_Pointer_Repository::ACE_Based_Pointer_Repository (void)
00033 {
00034   ACE_TRACE ("ACE_Based_Pointer_Repository::ACE_Based_Pointer_Repository");
00035   ACE_NEW (this->rep_,
00036            ACE_Based_Pointer_Repository_Rep);
00037 }
00038 
00039 ACE_Based_Pointer_Repository::~ACE_Based_Pointer_Repository (void)
00040 {
00041   ACE_TRACE ("ACE_Based_Pointer_Repository::~ACE_Based_Pointer_Repository");
00042   delete this->rep_;
00043 }
00044 
00045 // Search for appropriate base address in repository
00046 
00047 int
00048 ACE_Based_Pointer_Repository::find (void *addr,
00049                                     void *&base_addr)
00050 {
00051   ACE_TRACE ("ACE_Based_Pointer_Repository::find");
00052   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->rep_->lock_, -1);
00053   ACE_Based_Pointer_Repository_Rep::MAP_ENTRY *ce = 0;
00054 
00055   for (ACE_Based_Pointer_Repository_Rep::MAP_ITERATOR iter (this->rep_->addr_map_);
00056        iter.next (ce) != 0;
00057        iter.advance ())
00058     // Check to see if <addr> is within any of the regions.
00059     if (addr >= ce->ext_id_
00060         && addr < ((char *) ce->ext_id_ + ce->int_id_))
00061       {
00062         // Assign the base address.
00063         base_addr = ce->ext_id_;
00064         return 1;
00065       }
00066 
00067   // Assume base address 0 (e.g., if new'ed).
00068   base_addr = 0;
00069   return 0;
00070 }
00071 
00072 // Bind a new entry to the repository or update the size of an
00073 // existing entry.
00074 
00075 int
00076 ACE_Based_Pointer_Repository::bind (void *addr,
00077                                     size_t size)
00078 {
00079   ACE_TRACE ("ACE_Based_Pointer_Repository::bind");
00080   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->rep_->lock_, -1);
00081 
00082   return this->rep_->addr_map_.rebind (addr, size);
00083 }
00084 
00085 // Unbind a base from the repository.
00086 
00087 int
00088 ACE_Based_Pointer_Repository::unbind (void *addr)
00089 {
00090   ACE_TRACE ("ACE_Based_Pointer_Repository::unbind");
00091   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->rep_->lock_, -1);
00092   ACE_Based_Pointer_Repository_Rep::MAP_ENTRY *ce = 0;
00093 
00094   // Search for service handlers that requested notification.
00095 
00096   for (ACE_Based_Pointer_Repository_Rep::MAP_ITERATOR iter (this->rep_->addr_map_);
00097        iter.next (ce) != 0;
00098        iter.advance ())
00099     {
00100       // Check to see if <addr> is within any of the regions and if
00101       // so, unbind the key from the map.
00102       if (addr >= ce->ext_id_
00103           && addr < ((char *) ce->ext_id_ + ce->int_id_))
00104         // Unbind base address.
00105         return this->rep_->addr_map_.unbind (ce->ext_id_);
00106     }
00107 
00108   return 0;
00109 }
00110 
00111 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00112 template class ACE_Singleton <ACE_Based_Pointer_Repository, ACE_SYNCH_RW_MUTEX>;
00113 template class ACE_Map_Entry<void *, size_t>;
00114 template class ACE_Map_Manager<void *, size_t, ACE_Null_Mutex>;
00115 template class ACE_Map_Iterator<void *, size_t, ACE_Null_Mutex>;
00116 template class ACE_Map_Reverse_Iterator<void *, size_t, ACE_Null_Mutex>;
00117 template class ACE_Map_Iterator_Base<void *, size_t, ACE_Null_Mutex>;
00118 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00119 #pragma instantiate ACE_Singleton <ACE_Based_Pointer_Repository, ACE_SYNCH_RW_MUTEX>
00120 #pragma instantiate ACE_Map_Entry<void *, size_t>
00121 #pragma instantiate ACE_Map_Manager<void *, size_t, ACE_Null_Mutex>
00122 #pragma instantiate ACE_Map_Iterator<void *, size_t, ACE_Null_Mutex>
00123 #pragma instantiate ACE_Map_Reverse_Iterator<void *, size_t, ACE_Null_Mutex>
00124 #pragma instantiate ACE_Map_Iterator_Base<void *, size_t, ACE_Null_Mutex>
00125 #elif defined (__GNUC__) && (defined (_AIX) || defined (__hpux))
00126 template ACE_Singleton<ACE_Based_Pointer_Repository, ACE_SYNCH_RW_MUTEX> *
00127   ACE_Singleton<ACE_Based_Pointer_Repository, ACE_SYNCH_RW_MUTEX>::singleton_;
00128 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

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