Define a map abstraction that associates EXT_IDs with INT_IDs. More...
#include <Map_Manager.h>
Public Types | |
typedef EXT_ID | KEY |
typedef INT_ID | VALUE |
typedef ACE_LOCK | lock_type |
typedef ACE_Map_Entry< EXT_ID, INT_ID > | ENTRY |
typedef ACE_Map_Iterator < EXT_ID, INT_ID, ACE_LOCK > | ITERATOR |
typedef ACE_Map_Const_Iterator < EXT_ID, INT_ID, ACE_LOCK > | CONST_ITERATOR |
typedef ACE_Map_Reverse_Iterator < EXT_ID, INT_ID, ACE_LOCK > | REVERSE_ITERATOR |
typedef ACE_Map_Iterator < EXT_ID, INT_ID, ACE_LOCK > | iterator |
typedef ACE_Map_Const_Iterator < EXT_ID, INT_ID, ACE_LOCK > | const_iterator |
typedef ACE_Map_Reverse_Iterator < EXT_ID, INT_ID, ACE_LOCK > | reverse_iterator |
Public Member Functions | |
ACE_Map_Manager (ACE_Allocator *alloc=0) | |
Initialize a ACE_Map_Manager with the ACE_DEFAULT_MAP_SIZE. | |
ACE_Map_Manager (size_t size, ACE_Allocator *alloc=0) | |
Initialize a ACE_Map_Manager with size entries. | |
int | open (size_t length=ACE_DEFAULT_MAP_SIZE, ACE_Allocator *alloc=0) |
Initialize a ACE_Map_Manager with size length. | |
int | close (void) |
~ACE_Map_Manager (void) | |
int | bind (const EXT_ID &ext_id, const INT_ID &int_id) |
int | rebind (const EXT_ID &ext_id, const INT_ID &int_id, EXT_ID &old_ext_id, INT_ID &old_int_id) |
int | rebind (const EXT_ID &ext_id, const INT_ID &int_id, INT_ID &old_int_id) |
int | rebind (const EXT_ID &ext_id, const INT_ID &int_id) |
int | trybind (const EXT_ID &ext_id, INT_ID &int_id) |
int | find (const EXT_ID &ext_id, INT_ID &int_id) const |
int | find (const EXT_ID &ext_id) const |
Returns 0 if the ext_id is in the mapping, otherwise -1. | |
int | unbind (const EXT_ID &ext_id) |
int | unbind (const EXT_ID &ext_id, INT_ID &int_id) |
void | unbind_all (void) |
size_t | current_size (void) const |
Return the current size of the map. | |
size_t | total_size (void) const |
Return the total size of the map. | |
ACE_LOCK & | mutex (void) |
void | dump (void) const |
Dump the state of an object. | |
ACE_Map_Iterator< EXT_ID, INT_ID, ACE_LOCK > | begin (void) |
Return forward iterator. | |
ACE_Map_Iterator< EXT_ID, INT_ID, ACE_LOCK > | end (void) |
ACE_Map_Reverse_Iterator < EXT_ID, INT_ID, ACE_LOCK > | rbegin (void) |
Return reverse iterator. | |
ACE_Map_Reverse_Iterator < EXT_ID, INT_ID, ACE_LOCK > | rend (void) |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Protected Types | |
enum | { MAX_EXPONENTIAL = 64 * 1024, LINEAR_INCREASE = 32 * 1024 } |
Protected Member Functions | |
int | bind_i (const EXT_ID &ext_id, const INT_ID &int_id) |
int | shared_bind (const EXT_ID &ext_id, const INT_ID &int_id) |
int | rebind_i (const EXT_ID &ext_id, const INT_ID &int_id, EXT_ID &old_ext_id, INT_ID &old_int_id) |
int | rebind_i (const EXT_ID &ext_id, const INT_ID &int_id, INT_ID &old_int_id) |
int | rebind_i (const EXT_ID &ext_id, const INT_ID &int_id) |
int | trybind_i (const EXT_ID &ext_id, INT_ID &int_id) |
int | find_i (const EXT_ID &ext_id, INT_ID &int_id) |
int | find_and_return_index (const EXT_ID &ext_id, ACE_UINT32 &slot) |
int | unbind_i (const EXT_ID &ext_id, INT_ID &int_id) |
int | unbind_i (const EXT_ID &ext_id) |
int | unbind_and_return_index (const EXT_ID &ext_id, ACE_UINT32 &slot) |
void | unbind_slot (ACE_UINT32 slot) |
Unbind slot. | |
int | resize_i (ACE_UINT32 size) |
Resize the map. Must be called with locks held. | |
int | close_i (void) |
Close down a <Map_Manager>. Must be called with locks held. | |
int | equal (const EXT_ID &id1, const EXT_ID &id2) |
ACE_UINT32 | new_size (void) |
void | free_search_structure (void) |
ACE_UINT32 | free_list_id (void) const |
Id of the free list sentinel. | |
ACE_UINT32 | occupied_list_id (void) const |
Id of the occupied list sentinel. | |
int | next_free (ACE_UINT32 &slot) |
Finds the next free slot. | |
void | move_from_free_list_to_occupied_list (ACE_UINT32 slot) |
Move from free list to occupied list. | |
void | move_from_occupied_list_to_free_list (ACE_UINT32 slot) |
Move from occupied list to free list. | |
void | shared_move (ACE_UINT32 slot, ACE_Map_Entry< EXT_ID, INT_ID > ¤t_list, ACE_UINT32 current_list_id, ACE_Map_Entry< EXT_ID, INT_ID > &new_list, ACE_UINT32 new_list_id) |
Move helper. | |
Protected Attributes | |
ACE_Allocator * | allocator_ |
Pointer to a memory allocator. | |
ACE_LOCK | lock_ |
Synchronization variable for the MT_SAFE ACE_Map_Manager. | |
ACE_Map_Entry< EXT_ID, INT_ID > * | search_structure_ |
Implement the Map as a resizeable array of ACE_Map_Entry. | |
ACE_UINT32 | total_size_ |
Total number of elements in this->search_structure_. | |
ACE_UINT32 | cur_size_ |
Current size of the map. | |
ACE_Map_Entry< EXT_ID, INT_ID > | free_list_ |
Free list. | |
ACE_Map_Entry< EXT_ID, INT_ID > | occupied_list_ |
Occupied list. | |
Private Member Functions | |
void | operator= (const ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK > &) |
ACE_Map_Manager (const ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK > &) | |
Friends | |
class | ACE_Map_Iterator_Base< EXT_ID, INT_ID, ACE_LOCK > |
class | ACE_Map_Const_Iterator_Base< EXT_ID, INT_ID, ACE_LOCK > |
class | ACE_Map_Iterator< EXT_ID, INT_ID, ACE_LOCK > |
class | ACE_Map_Const_Iterator< EXT_ID, INT_ID, ACE_LOCK > |
class | ACE_Map_Reverse_Iterator< EXT_ID, INT_ID, ACE_LOCK > |
Define a map abstraction that associates EXT_IDs with INT_IDs.
The EXT_ID must support operator==
. This constraint can be alleviated via template specialization, as shown in the $ACE_ROOT/tests/Conn_Test.cpp test. This class uses an ACE_Allocator to allocate memory. The user can make this a persistant class by providing an ACE_Allocator with a persistable memory pool. This implementation of a map uses an array, which is searched linearly. For more efficient searching you should use the ACE_Hash_Map_Manager.
Definition at line 129 of file Map_Manager.h.
typedef ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::CONST_ITERATOR |
Definition at line 144 of file Map_Manager.h.
typedef ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::const_iterator |
Definition at line 148 of file Map_Manager.h.
typedef ACE_Map_Entry<EXT_ID, INT_ID> ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::ENTRY |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 142 of file Map_Manager.h.
typedef ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::ITERATOR |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 143 of file Map_Manager.h.
typedef ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::iterator |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 147 of file Map_Manager.h.
typedef EXT_ID ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::KEY |
Definition at line 139 of file Map_Manager.h.
typedef ACE_LOCK ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::lock_type |
Definition at line 141 of file Map_Manager.h.
typedef ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::reverse_iterator |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 149 of file Map_Manager.h.
typedef ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::REVERSE_ITERATOR |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 145 of file Map_Manager.h.
typedef INT_ID ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::VALUE |
Definition at line 140 of file Map_Manager.h.
anonymous enum [protected] |
MAX_EXPONENTIAL |
Grow map exponentially up to 64K. |
LINEAR_INCREASE |
Afterwards grow in chunks of 32K. |
Definition at line 430 of file Map_Manager.h.
{ /// Grow map exponentially up to 64K MAX_EXPONENTIAL = 64 * 1024, /// Afterwards grow in chunks of 32K LINEAR_INCREASE = 32 * 1024 };
ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::ACE_Map_Manager | ( | ACE_Allocator * | alloc = 0 |
) | [inline] |
Initialize a ACE_Map_Manager with the ACE_DEFAULT_MAP_SIZE.
Definition at line 63 of file Map_Manager.inl.
: allocator_ (0), search_structure_ (0), total_size_ (0), cur_size_ (0) { if (this->open (ACE_DEFAULT_MAP_SIZE, alloc) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("ACE_Map_Manager\n"))); }
ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::ACE_Map_Manager | ( | size_t | size, | |
ACE_Allocator * | alloc = 0 | |||
) | [inline] |
Initialize a ACE_Map_Manager with size entries.
Definition at line 51 of file Map_Manager.inl.
: allocator_ (0), search_structure_ (0), total_size_ (0), cur_size_ (0) { if (this->open (size, alloc) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("ACE_Map_Manager\n"))); }
ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::~ACE_Map_Manager | ( | void | ) | [inline] |
Close down a ACE_Map_Manager and release dynamically allocated resources.
Definition at line 82 of file Map_Manager.inl.
{ this->close (); }
ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::ACE_Map_Manager | ( | const ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK > & | ) | [private] |
ACE_Map_Iterator< EXT_ID, INT_ID, ACE_LOCK > ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::begin | ( | void | ) | [inline] |
Return forward iterator.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 255 of file Map_Manager.inl.
{ return ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::bind | ( | const EXT_ID & | ext_id, | |
const INT_ID & | int_id | |||
) | [inline] |
Associate ext_id with int_id. If ext_id is already in the map then the ACE_Map_Entry is not changed.
0 | If a new entry is bound successfully. | |
1 | If an attempt is made to bind an existing entry. | |
-1 | If failures occur. |
Definition at line 88 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->bind_i (ext_id, int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::bind_i | ( | const EXT_ID & | ext_id, | |
const INT_ID & | int_id | |||
) | [protected] |
Performs the binding of ext_id to int_id. Must be called with locks held.
Definition at line 83 of file Map_Manager.cpp.
{ // Try to find the key. ACE_UINT32 slot = 0; int result = this->find_and_return_index (ext_id, slot); if (result == 0) // We found the key. Nothing to change. return 1; else // We didn't find the key. return this->shared_bind (ext_id, int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::close | ( | void | ) | [inline] |
Close down a ACE_Map_Manager and release dynamically allocated resources.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 74 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->close_i (); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::close_i | ( | void | ) | [protected] |
Close down a <Map_Manager>. Must be called with locks held.
Definition at line 62 of file Map_Manager.cpp.
{ // Free entries. this->free_search_structure (); // Reset sizes. this->total_size_ = 0; this->cur_size_ = 0; // Reset circular free list. this->free_list_.next (this->free_list_id ()); this->free_list_.prev (this->free_list_id ()); // Reset circular occupied list. this->occupied_list_.next (this->occupied_list_id ()); this->occupied_list_.prev (this->occupied_list_id ()); return 0; }
size_t ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::current_size | ( | void | ) | const [inline] |
Return the current size of the map.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 192 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, static_cast<size_t> (-1)); return this->cur_size_; }
void ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::dump | ( | void | ) | const |
Dump the state of an object.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 611 of file Map_Manager.cpp.
{ #if defined (ACE_HAS_DUMP) ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("total_size_ = %d"), this->total_size_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ncur_size_ = %d"), this->cur_size_)); this->allocator_->dump (); this->lock_.dump (); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* ACE_HAS_DUMP */ }
ACE_Map_Iterator< EXT_ID, INT_ID, ACE_LOCK > ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::end | ( | void | ) | [inline] |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 262 of file Map_Manager.inl.
{ return ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::equal | ( | const EXT_ID & | id1, | |
const EXT_ID & | id2 | |||
) | [inline, protected] |
Returns 1 if <id1> == <id2>, else 0. This is defined as a separate method to facilitate template specialization.
Definition at line 232 of file Map_Manager.inl.
{
return id1 == id2;
}
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find | ( | const EXT_ID & | ext_id | ) | const [inline] |
Returns 0 if the ext_id is in the mapping, otherwise -1.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 144 of file Map_Manager.inl.
{ ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> *nc_this = (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> *) this; ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, nc_this->lock_, -1); ACE_UINT32 slot = 0; return nc_this->find_and_return_index (ext_id, slot); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find | ( | const EXT_ID & | ext_id, | |
INT_ID & | int_id | |||
) | const [inline] |
Locate ext_id and pass out parameter via int_id.
0 | If found. | |
-1 | If not found. |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 155 of file Map_Manager.inl.
{ ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> *nc_this = (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> *) this; ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, nc_this->lock_, -1); return nc_this->find_i (ext_id, int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find_and_return_index | ( | const EXT_ID & | ext_id, | |
ACE_UINT32 & | slot | |||
) | [protected] |
Performs a find using ext_id as the key. Must be called with locks held.
Definition at line 363 of file Map_Manager.cpp.
{ // Go through the entire occupied list looking for the key. for (ACE_UINT32 i = this->occupied_list_.next (); i != this->occupied_list_id (); i = this->search_structure_[i].next ()) { #if defined (ACE_HAS_LAZY_MAP_MANAGER) if (this->search_structure_[i].free_) continue; #endif /* ACE_HAS_LAZY_MAP_MANAGER */ if (this->equal (this->search_structure_[i].ext_id_, ext_id)) { // If found, return slot. slot = i; return 0; } } // Key was not found. return -1; }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::find_i | ( | const EXT_ID & | ext_id, | |
INT_ID & | int_id | |||
) | [protected] |
Performs a find of int_id using ext_id as the key. Must be called with locks held.
Definition at line 424 of file Map_Manager.cpp.
{ // Try to find the key. ACE_UINT32 slot = 0; int result = this->find_and_return_index (ext_id, slot); if (result == 0) // Key was found. Make a copy of value. int_id = this->search_structure_[slot].int_id_; return result; }
ACE_UINT32 ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::free_list_id | ( | void | ) | const [inline, protected] |
Id of the free list sentinel.
Definition at line 239 of file Map_Manager.inl.
{ // If you change ~0, please change // ACE_Active_Map_Manager_Key::ACE_Active_Map_Manager_Key() // accordingly. return (ACE_UINT32) ~0; }
void ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::free_search_structure | ( | void | ) | [protected] |
Explicitly call the destructors and free up the <search_structure_>.
Definition at line 573 of file Map_Manager.cpp.
{ // Free up the structure. if (this->search_structure_ != 0) { for (ACE_UINT32 i = 0; i < this->total_size_; i++) // Explicitly call the destructor. { ENTRY *ss = &this->search_structure_[i]; // The "if" second argument results in a no-op instead of // deallocation. ACE_DES_FREE_TEMPLATE2 (ss, ACE_NOOP, ACE_Map_Entry, EXT_ID, INT_ID); } // Actually free the memory. this->allocator_->free (this->search_structure_); this->search_structure_ = 0; } }
void ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::move_from_free_list_to_occupied_list | ( | ACE_UINT32 | slot | ) | [inline, protected] |
Move from free list to occupied list.
Definition at line 212 of file Map_Manager.inl.
{ this->shared_move (slot, this->free_list_, this->free_list_id (), this->occupied_list_, this->occupied_list_id ()); }
void ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::move_from_occupied_list_to_free_list | ( | ACE_UINT32 | slot | ) | [inline, protected] |
Move from occupied list to free list.
Definition at line 222 of file Map_Manager.inl.
{ this->shared_move (slot, this->occupied_list_, this->occupied_list_id (), this->free_list_, this->free_list_id ()); }
ACE_LOCK & ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::mutex | ( | void | ) | [inline] |
Returns a reference to the underlying ACE_LOCK. This makes it possible to acquire the lock explicitly, which can be useful in some cases if you instantiate the ACE_Atomic_Op with an ACE_Recursive_Mutex or ACE_Process_Mutex, or if you need to guard the state of an iterator.
Definition at line 206 of file Map_Manager.inl.
{ return this->lock_; }
ACE_UINT32 ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::new_size | ( | void | ) | [protected] |
This function returns the new size of the Map Manager. This function is called when we run out of room and need to resize.
Definition at line 556 of file Map_Manager.cpp.
{ // Calculate the new size. ACE_UINT32 current_size = this->total_size_; if (current_size < MAX_EXPONENTIAL) // Exponentially increase if we haven't reached MAX_EXPONENTIAL. current_size *= 2; else // Linear increase if we have reached MAX_EXPONENTIAL. current_size += LINEAR_INCREASE; // This should be the new size. return current_size; }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::next_free | ( | ACE_UINT32 & | slot | ) | [protected] |
Finds the next free slot.
Definition at line 101 of file Map_Manager.cpp.
{ // Look in the free list for an empty slot. free_slot = this->free_list_.next (); // If we do find a free slot, return successfully. if (free_slot != this->free_list_id ()) return 0; #if defined (ACE_HAS_LAZY_MAP_MANAGER) // Move any free slots from occupied list to free list. this->move_all_free_slots_from_occupied_list (); // Try again in case we found any free slots in the occupied list. free_slot = this->free_list_.next (); // If we do find a free slot, return successfully. if (free_slot != this->free_list_id ()) return 0; #endif /* ACE_HAS_LAZY_MAP_MANAGER */ // Resize the map. int result = this->resize_i (this->new_size ()); // Check for errors. if (result == 0) // New free slot. free_slot = this->free_list_.next (); return result; }
ACE_UINT32 ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::occupied_list_id | ( | void | ) | const [inline, protected] |
Id of the occupied list sentinel.
Definition at line 248 of file Map_Manager.inl.
{
return (ACE_UINT32) ~1;
}
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::open | ( | size_t | length = ACE_DEFAULT_MAP_SIZE , |
|
ACE_Allocator * | alloc = 0 | |||
) |
Initialize a ACE_Map_Manager with size length.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 29 of file Map_Manager.cpp.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); // Close old map (if any). this->close_i (); // Use the user specified allocator or the default singleton one. if (alloc == 0) alloc = ACE_Allocator::instance (); this->allocator_ = alloc; // This assertion is here to help track a situation that shouldn't // happen. ACE_ASSERT (size != 0); // Active_Map_Manager depends on the <slot_index_> being of fixed // size. It cannot be size_t because size_t is 64-bits on 64-bit // platform and 32-bits on 32-bit platforms. Size of the <slot_index_> // has to be consistent across platforms. ACE_UIN32 is chosen as // ACE_UIN32_MAX is big enough. The assert is to ensure that the user // doesn't open the ACE_Map_Manager with a bigger size than we can // handle. ACE_ASSERT (size <= ACE_UINT32_MAX); // Resize from 0 to <size>. Note that this will also set up the // circular free list. return this->resize_i ((ACE_UINT32) size); }
void ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::operator= | ( | const ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK > & | ) | [private] |
ACE_Map_Reverse_Iterator< EXT_ID, INT_ID, ACE_LOCK > ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::rbegin | ( | void | ) | [inline] |
Return reverse iterator.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 269 of file Map_Manager.inl.
{ return ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::rebind | ( | const EXT_ID & | ext_id, | |
const INT_ID & | int_id, | |||
EXT_ID & | old_ext_id, | |||
INT_ID & | old_int_id | |||
) | [inline] |
Reassociate ext_id with int_id. If ext_id is not in the map then behaves just like bind(). Otherwise, store the old values of ext_id and int_id into the "out" parameters and rebind the new parameters. This is very useful if you need to have an atomic way of updating <Map_Entries> and you also need full control over memory allocation.
0 | If a new entry is bound successfully. | |
1 | If an existing entry was rebound. | |
-1 | If failures occur. |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 98 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->rebind_i (ext_id, int_id, old_ext_id, old_int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::rebind | ( | const EXT_ID & | ext_id, | |
const INT_ID & | int_id, | |||
INT_ID & | old_int_id | |||
) | [inline] |
Reassociate ext_id with int_id. If ext_id is not in the map then behaves just like bind(). Otherwise, store the old values of int_id into the "out" parameter and rebind the new parameters.
0 | If a new entry is bound successfully. | |
1 | If an existing entry was rebound. | |
-1 | If failures occur. |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 112 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->rebind_i (ext_id, int_id, old_int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::rebind | ( | const EXT_ID & | ext_id, | |
const INT_ID & | int_id | |||
) | [inline] |
Reassociate ext_id with int_id. Old values in the map are ignored.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 124 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->rebind_i (ext_id, int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::rebind_i | ( | const EXT_ID & | ext_id, | |
const INT_ID & | int_id, | |||
EXT_ID & | old_ext_id, | |||
INT_ID & | old_int_id | |||
) | [protected] |
Performs a rebinding of <ext_it> to int_id. Also, recovers old values. Must be called with locks held.
Definition at line 256 of file Map_Manager.cpp.
{ // First try to find the key. ACE_UINT32 slot = 0; int result = this->find_and_return_index (ext_id, slot); if (result == 0) { // We found it, so make copies of the old entries and rebind // current entries. ENTRY &ss = this->search_structure_[slot]; old_ext_id = ss.ext_id_; old_int_id = ss.int_id_; ss.ext_id_ = ext_id; ss.int_id_ = int_id; // Sync changed entry. this->allocator_->sync (&ss, sizeof ss); return 1; } else // We didn't find it, so let's add it. return this->shared_bind (ext_id, int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::rebind_i | ( | const EXT_ID & | ext_id, | |
const INT_ID & | int_id, | |||
INT_ID & | old_int_id | |||
) | [protected] |
Performs a rebinding of <ext_it> to int_id. Also, recovers old values. Must be called with locks held.
Definition at line 287 of file Map_Manager.cpp.
{ // First try to find the key. ACE_UINT32 slot = 0; int result = this->find_and_return_index (ext_id, slot); if (result == 0) { // We found it, so make copies of the old entries and rebind // current entries. ENTRY &ss = this->search_structure_[slot]; old_int_id = ss.int_id_; ss.ext_id_ = ext_id; ss.int_id_ = int_id; // Sync changed entry. this->allocator_->sync (&ss, sizeof ss); return 1; } else // We didn't find it, so let's add it. return this->shared_bind (ext_id, int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::rebind_i | ( | const EXT_ID & | ext_id, | |
const INT_ID & | int_id | |||
) | [protected] |
Performs a rebinding of <ext_it> to int_id. Must be called with locks held.
Definition at line 316 of file Map_Manager.cpp.
{ // First try to find the key. ACE_UINT32 slot = 0; int result = this->find_and_return_index (ext_id, slot); if (result == 0) { // We found it, so rebind current entries. ENTRY &ss = this->search_structure_[slot]; ss.ext_id_ = ext_id; ss.int_id_ = int_id; // Sync changed entry. this->allocator_->sync (&ss, sizeof ss); return 1; } else // We didn't find it, so let's add it. return this->shared_bind (ext_id, int_id); }
ACE_Map_Reverse_Iterator< EXT_ID, INT_ID, ACE_LOCK > ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::rend | ( | void | ) | [inline] |
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 276 of file Map_Manager.inl.
{ return ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::resize_i | ( | ACE_UINT32 | size | ) | [protected] |
Resize the map. Must be called with locks held.
Definition at line 493 of file Map_Manager.cpp.
{ ACE_UINT32 i; ENTRY *temp = 0; // Allocate new memory. ACE_ALLOCATOR_RETURN (temp, (ENTRY *) this->allocator_->malloc (new_size * sizeof (ENTRY)), -1); // Copy over the occupied entires. for (i = this->occupied_list_.next (); i != this->occupied_list_id (); i = this->search_structure_[i].next ()) // Call the copy constructor using operator placement new. new (&(temp[i])) ENTRY (this->search_structure_[i]); // Copy over the free entires. for (i = this->free_list_.next (); i != this->free_list_id (); i = this->search_structure_[i].next ()) // Call the copy constructor using operator placement new. new (&(temp[i])) ENTRY (this->search_structure_[i]); // Construct the new elements. for (i = this->total_size_; i < new_size; i++) { // Call the constructor for each element in the array using // operator placement new. Note that this requires a default // constructor for <EXT_ID> and <INT_ID>. new (&(temp[i])) ENTRY; temp[i].next (i + 1); temp[i].prev (i - 1); #if defined (ACE_HAS_LAZY_MAP_MANAGER) // Even though this slot is initially free, we need the <free_> // flag to be zero so that we don't have to set it when the slot // is moved to the occupied list. In addition, this flag has no // meaning while this slot is in the free list. temp[i].free_ = false; #endif /* ACE_HAS_LAZY_MAP_MANAGER */ } // Add new entries to the free list. this->free_list_.next (this->total_size_); this->free_list_.prev (new_size - 1); temp[new_size - 1].next (this->free_list_id ()); temp[this->total_size_].prev (this->free_list_id ()); // Remove/free old elements, update the new totoal size. this->free_search_structure (); this->total_size_ = new_size; // Start using new elements. this->search_structure_ = temp; return 0; }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::shared_bind | ( | const EXT_ID & | ext_id, | |
const INT_ID & | int_id | |||
) | [protected] |
Bind an entry (without finding first). Must be called with locks held.
Definition at line 229 of file Map_Manager.cpp.
{ // This function assumes that the find() has already been done, and // therefore, simply adds to the map. // Find an empty slot. ACE_UINT32 slot = 0; int result = this->next_free (slot); if (result == 0) { // Copy key and value. this->search_structure_[slot].int_id_ = int_id; this->search_structure_[slot].ext_id_ = ext_id; // Move from free list to occupied list this->move_from_free_list_to_occupied_list (slot); // Update the current size. ++this->cur_size_; } return result; }
void ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::shared_move | ( | ACE_UINT32 | slot, | |
ACE_Map_Entry< EXT_ID, INT_ID > & | current_list, | |||
ACE_UINT32 | current_list_id, | |||
ACE_Map_Entry< EXT_ID, INT_ID > & | new_list, | |||
ACE_UINT32 | new_list_id | |||
) | [protected] |
Move helper.
Definition at line 184 of file Map_Manager.cpp.
{ // Grab the entry. ENTRY &entry = this->search_structure_[slot]; // Remove from current list. // Fix the entry before us. ACE_UINT32 current_list_prev = entry.prev (); if (current_list_prev == current_list_id) current_list.next (entry.next ()); else this->search_structure_[current_list_prev].next (entry.next ()); // Fix the entry after us. ACE_UINT32 current_list_next = entry.next (); if (current_list_next == current_list_id) current_list.prev (entry.prev ()); else this->search_structure_[current_list_next].prev (entry.prev ()); // Add to new list. // Fix us. ACE_UINT32 new_list_next = new_list.next (); entry.next (new_list_next); entry.prev (new_list_id); // Fix entry before us. new_list.next (slot); // Fix entry after us. if (new_list_next == new_list_id) new_list.prev (slot); else this->search_structure_[new_list_next].prev (slot); }
size_t ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::total_size | ( | void | ) | const [inline] |
Return the total size of the map.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 199 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, static_cast<size_t> (-1)); return this->total_size_; }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::trybind | ( | const EXT_ID & | ext_id, | |
INT_ID & | int_id | |||
) | [inline] |
Associate ext_id with int_id if and only if ext_id is not in the map. If ext_id is already in the map then the int_id parameter is overwritten with the existing value in the map
0 | If a new entry is bound successfully. | |
1 | If an attempt is made to bind an existing entry. | |
-1 | If failures occur. |
Definition at line 134 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->trybind_i (ext_id, int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::trybind_i | ( | const EXT_ID & | ext_id, | |
INT_ID & | int_id | |||
) | [protected] |
Performs a conditional bind of int_id using ext_id as the key. Must be called with locks held.
Definition at line 342 of file Map_Manager.cpp.
{ // Try to find the key. ACE_UINT32 slot = 0; int result = this->find_and_return_index (ext_id, slot); if (result == 0) { // Key was found. Make a copy of value, but *don't* update // anything in the map! int_id = this->search_structure_[slot].int_id_; return 1; } else // We didn't find it, so let's bind it! return this->bind_i (ext_id, int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::unbind | ( | const EXT_ID & | ext_id, | |
INT_ID & | int_id | |||
) | [inline] |
Break any association of ext_id. Returns the value of int_id in case the caller needs to deallocate memory. Returns 0 if successful, else -1.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 175 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->unbind_i (ext_id, int_id); }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::unbind | ( | const EXT_ID & | ext_id | ) | [inline] |
Unbind (remove) the ext_id from the map. Don't return the int_id to the caller (this is useful for collections where the int_ids are *not* dynamically allocated...) Returns 0 if successful, else -1.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 185 of file Map_Manager.inl.
{ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->unbind_i (ext_id); }
void ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::unbind_all | ( | void | ) |
Unbind all entires.
Definition at line 390 of file Map_Manager.cpp.
{ // Go through the entire occupied list. for (ACE_UINT32 i = this->occupied_list_.next (); i != this->occupied_list_id (); ) { // // Note the trick used here: Information about the current slot // is first noted; <i> then moves to the next occupied slot; // only after this is the slot (potentially) moved from the // occupied list to the free list. This order of things, i.e., // moving <i> before moving the free slot is necessary, // otherwise we'll forget which our next occupied slot is. // // Note information about current slot. ACE_Map_Entry<EXT_ID, INT_ID> ¤t_slot = this->search_structure_[i]; ACE_UINT32 position_of_current_slot = i; // Move <i> to next occupied slot. i = current_slot.next (); #if defined (ACE_HAS_LAZY_MAP_MANAGER) if (current_slot.free_) continue; #endif /* ACE_HAS_LAZY_MAP_MANAGER */ this->unbind_slot (position_of_current_slot); } }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::unbind_and_return_index | ( | const EXT_ID & | ext_id, | |
ACE_UINT32 & | slot | |||
) | [protected] |
Performs an unbind using ext_id as the key. Must be called with locks held.
Definition at line 439 of file Map_Manager.cpp.
{ // Try to find the key. int result = this->find_and_return_index (ext_id, slot); if (result == 0) this->unbind_slot (slot); return result; }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::unbind_i | ( | const EXT_ID & | ext_id, | |
INT_ID & | int_id | |||
) | [protected] |
Performs an unbind of int_id using ext_id as the key. Must be called with locks held.
Definition at line 478 of file Map_Manager.cpp.
{ // Unbind the entry. ACE_UINT32 slot = 0; int result = this->unbind_and_return_index (ext_id, slot); if (result == 0) // If found, copy the value. int_id = this->search_structure_[slot].int_id_; return result; }
int ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::unbind_i | ( | const EXT_ID & | ext_id | ) | [inline, protected] |
Performs an unbind using ext_id as the key. Must be called with locks held.
Definition at line 166 of file Map_Manager.inl.
{ // Unbind the entry. ACE_UINT32 slot = 0; return this->unbind_and_return_index (ext_id, slot); }
void ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::unbind_slot | ( | ACE_UINT32 | slot | ) | [protected] |
Unbind slot.
Definition at line 453 of file Map_Manager.cpp.
{ #if defined (ACE_HAS_LAZY_MAP_MANAGER) // // In the case of lazy map managers, the movement of free slots // from the occupied list to the free list is delayed until we // run out of free slots in the free list. // this->search_structure_[slot].free_ = true; #else // Move from occupied list to free list. this->move_from_occupied_list_to_free_list (slot); #endif /* ACE_HAS_LAZY_MAP_MANAGER */ // Update the current size. --this->cur_size_; }
friend class ACE_Map_Const_Iterator< EXT_ID, INT_ID, ACE_LOCK > [friend] |
Definition at line 135 of file Map_Manager.h.
friend class ACE_Map_Const_Iterator_Base< EXT_ID, INT_ID, ACE_LOCK > [friend] |
Definition at line 133 of file Map_Manager.h.
friend class ACE_Map_Iterator< EXT_ID, INT_ID, ACE_LOCK > [friend] |
Definition at line 134 of file Map_Manager.h.
friend class ACE_Map_Iterator_Base< EXT_ID, INT_ID, ACE_LOCK > [friend] |
Definition at line 132 of file Map_Manager.h.
friend class ACE_Map_Reverse_Iterator< EXT_ID, INT_ID, ACE_LOCK > [friend] |
Definition at line 136 of file Map_Manager.h.
ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::ACE_ALLOC_HOOK_DECLARE |
Declare the dynamic allocation hooks.
Reimplemented in ACE_Active_Map_Manager< T >, and ACE_Active_Map_Manager< ACE_Pair< KEY, VALUE > >.
Definition at line 288 of file Map_Manager.h.
ACE_Allocator* ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::allocator_ [protected] |
Pointer to a memory allocator.
Definition at line 410 of file Map_Manager.h.
ACE_UINT32 ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::cur_size_ [protected] |
Current size of the map.
Definition at line 422 of file Map_Manager.h.
ACE_Map_Entry<EXT_ID, INT_ID> ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::free_list_ [protected] |
Free list.
Definition at line 425 of file Map_Manager.h.
ACE_LOCK ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::lock_ [mutable, protected] |
Synchronization variable for the MT_SAFE ACE_Map_Manager.
Definition at line 413 of file Map_Manager.h.
ACE_Map_Entry<EXT_ID, INT_ID> ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::occupied_list_ [protected] |
Occupied list.
Definition at line 428 of file Map_Manager.h.
ACE_Map_Entry<EXT_ID, INT_ID>* ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::search_structure_ [protected] |
Implement the Map as a resizeable array of ACE_Map_Entry.
Definition at line 416 of file Map_Manager.h.
ACE_UINT32 ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::total_size_ [protected] |
Total number of elements in this->search_structure_.
Definition at line 419 of file Map_Manager.h.