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
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
27 typedef ACE_Map_Manager
<void *, size_t, ACE_Null_Mutex
> MAP_MANAGER
;
28 typedef ACE_Map_Iterator
<void *, size_t, ACE_Null_Mutex
> MAP_ITERATOR
;
29 typedef ACE_Map_Entry
<void *, size_t> MAP_ENTRY
;
31 /// Keeps track of the mapping between addresses and their associated
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 (void)
45 ACE_TRACE ("ACE_Based_Pointer_Repository::ACE_Based_Pointer_Repository");
47 ACE_Based_Pointer_Repository_Rep
);
50 ACE_Based_Pointer_Repository::~ACE_Based_Pointer_Repository (void)
52 ACE_TRACE ("ACE_Based_Pointer_Repository::~ACE_Based_Pointer_Repository");
56 // Search for appropriate base address in repository
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_
);
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_
;
77 // Assume base address 0 (e.g., if new'ed).
82 // Bind a new entry to the repository or update the size of an
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.
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_
);
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_
);
120 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton
, ACE_Based_Pointer_Repository
, ACE_SYNCH_RW_MUTEX
);
123 ACE_END_VERSIONED_NAMESPACE_DECL