Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / ace / Based_Pointer_Repository.cpp
blob3dd1a4e3e546fafa466ef1c9188fe1f74d17b3dc
1 #include "ace/Map_Manager.h"
2 #include "ace/Based_Pointer_Repository.h"
3 #include "ace/Guard_T.h"
4 #include "ace/Null_Mutex.h"
5 #include "ace/Synch_Traits.h"
6 #include "ace/RW_Thread_Mutex.h"
8 #if defined (ACE_HAS_ALLOC_HOOKS)
9 # include "ace/Malloc_Base.h"
10 #endif /* ACE_HAS_ALLOC_HOOKS */
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 /**
15 * @class ACE_Based_Pointer_Repository_Rep
17 * @brief Implementation for the ACE_Based_Pointer_Repository.
19 * Every memory pool in ACE binds it's mapping base address and
20 * the mapped size to this repository every time it maps/remaps a
21 * new chunk of memory successfully.
23 class ACE_Based_Pointer_Repository_Rep
25 public:
26 // Useful typedefs.
27 using MAP_MANAGER = ACE_Map_Manager<void *, size_t, ACE_Null_Mutex>;
28 using MAP_ITERATOR = ACE_Map_Iterator<void *, size_t, ACE_Null_Mutex>;
29 using MAP_ENTRY = ACE_Map_Entry<void *, size_t>;
31 /// Keeps track of the mapping between addresses and their associated
32 /// values.
33 MAP_MANAGER addr_map_;
35 /// Synchronize concurrent access to the map.
36 ACE_SYNCH_MUTEX lock_;
38 ACE_ALLOC_HOOK_DECLARE;
41 ACE_ALLOC_HOOK_DEFINE(ACE_Based_Pointer_Repository_Rep);
43 ACE_Based_Pointer_Repository::ACE_Based_Pointer_Repository ()
45 ACE_TRACE ("ACE_Based_Pointer_Repository::ACE_Based_Pointer_Repository");
46 ACE_NEW (this->rep_,
47 ACE_Based_Pointer_Repository_Rep);
50 ACE_Based_Pointer_Repository::~ACE_Based_Pointer_Repository ()
52 ACE_TRACE ("ACE_Based_Pointer_Repository::~ACE_Based_Pointer_Repository");
53 delete this->rep_;
56 // Search for appropriate base address in repository
58 int
59 ACE_Based_Pointer_Repository::find (void *addr, void *&base_addr)
61 ACE_TRACE ("ACE_Based_Pointer_Repository::find");
62 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->rep_->lock_, -1);
63 ACE_Based_Pointer_Repository_Rep::MAP_ENTRY *ce = 0;
65 for (ACE_Based_Pointer_Repository_Rep::MAP_ITERATOR iter (this->rep_->addr_map_);
66 iter.next (ce) != 0;
67 iter.advance ())
68 // Check to see if <addr> is within any of the regions.
69 if (addr >= ce->ext_id_
70 && addr < ((char *)ce->ext_id_ + ce->int_id_))
72 // Assign the base address.
73 base_addr = ce->ext_id_;
74 return 1;
77 // Assume base address 0 (e.g., if new'ed).
78 base_addr = 0;
79 return 0;
82 // Bind a new entry to the repository or update the size of an
83 // existing entry.
85 int
86 ACE_Based_Pointer_Repository::bind (void *addr, size_t size)
88 ACE_TRACE ("ACE_Based_Pointer_Repository::bind");
89 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->rep_->lock_, -1);
91 return this->rep_->addr_map_.rebind (addr, size);
94 // Unbind a base from the repository.
96 int
97 ACE_Based_Pointer_Repository::unbind (void *addr)
99 ACE_TRACE ("ACE_Based_Pointer_Repository::unbind");
100 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->rep_->lock_, -1);
101 ACE_Based_Pointer_Repository_Rep::MAP_ENTRY *ce = 0;
103 // Search for service handlers that requested notification.
105 for (ACE_Based_Pointer_Repository_Rep::MAP_ITERATOR iter (this->rep_->addr_map_);
106 iter.next (ce) != 0;
107 iter.advance ())
109 // Check to see if <addr> is within any of the regions and if
110 // so, unbind the key from the map.
111 if (addr >= ce->ext_id_
112 && addr < ((char *)ce->ext_id_ + ce->int_id_))
113 // Unbind base address.
114 return this->rep_->addr_map_.unbind (ce->ext_id_);
117 return 0;
120 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton, ACE_Based_Pointer_Repository, ACE_SYNCH_RW_MUTEX);
123 ACE_END_VERSIONED_NAMESPACE_DECL