// -*- C++ -*- // // $Id$ #include "ace/Guard_T.h" #include "ace/Log_Msg.h" ACE_BEGIN_VERSIONED_NAMESPACE_DECL template ACE_INLINE ACE_Map_Entry::ACE_Map_Entry (void) : next_ (0), prev_ (0) #if defined (ACE_HAS_LAZY_MAP_MANAGER) , free_ (1) #endif /* ACE_HAS_LAZY_MAP_MANAGER */ { } template ACE_INLINE ACE_Map_Entry::~ACE_Map_Entry (void) { // No-op just to keep some compilers happy... } template ACE_INLINE ACE_UINT32 ACE_Map_Entry::next (void) const { return this->next_; } template ACE_INLINE void ACE_Map_Entry::next (ACE_UINT32 n) { this->next_ = n; } template ACE_INLINE ACE_UINT32 ACE_Map_Entry::prev (void) const { return this->prev_; } template ACE_INLINE void ACE_Map_Entry::prev (ACE_UINT32 p) { this->prev_ = p; } template ACE_INLINE ACE_Map_Manager::ACE_Map_Manager (size_t size, ACE_Allocator *alloc) : allocator_ (0), search_structure_ (0), total_size_ (0), cur_size_ (0) { if (this->open (size, alloc) == -1) ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("ACE_Map_Manager\n"))); } template ACE_INLINE ACE_Map_Manager::ACE_Map_Manager (ACE_Allocator *alloc) : 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_LIB_TEXT ("ACE_Map_Manager\n"))); } template ACE_INLINE int ACE_Map_Manager::close (void) { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->close_i (); } template ACE_INLINE ACE_Map_Manager::~ACE_Map_Manager (void) { this->close (); } template ACE_INLINE int ACE_Map_Manager::bind (const EXT_ID &ext_id, const INT_ID &int_id) { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->bind_i (ext_id, int_id); } template ACE_INLINE int ACE_Map_Manager::rebind (const EXT_ID &ext_id, const INT_ID &int_id, EXT_ID &old_ext_id, INT_ID &old_int_id) { 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); } template ACE_INLINE int ACE_Map_Manager::rebind (const EXT_ID &ext_id, const INT_ID &int_id, INT_ID &old_int_id) { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->rebind_i (ext_id, int_id, old_int_id); } template ACE_INLINE int ACE_Map_Manager::rebind (const EXT_ID &ext_id, const INT_ID &int_id) { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->rebind_i (ext_id, int_id); } template ACE_INLINE int ACE_Map_Manager::trybind (const EXT_ID &ext_id, INT_ID &int_id) { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->trybind_i (ext_id, int_id); } template ACE_INLINE int ACE_Map_Manager::find (const EXT_ID &ext_id) const { ACE_Map_Manager *nc_this = (ACE_Map_Manager *) 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); } template ACE_INLINE int ACE_Map_Manager::find (const EXT_ID &ext_id, INT_ID &int_id) const { ACE_Map_Manager *nc_this = (ACE_Map_Manager *) this; ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, nc_this->lock_, -1); return nc_this->find_i (ext_id, int_id); } template ACE_INLINE int ACE_Map_Manager::unbind_i (const EXT_ID &ext_id) { // Unbind the entry. ACE_UINT32 slot = 0; return this->unbind_and_return_index (ext_id, slot); } template ACE_INLINE int ACE_Map_Manager::unbind (const EXT_ID &ext_id, INT_ID &int_id) { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->unbind_i (ext_id, int_id); } template ACE_INLINE int ACE_Map_Manager::unbind (const EXT_ID &ext_id) { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); return this->unbind_i (ext_id); } template ACE_INLINE size_t ACE_Map_Manager::current_size (void) const { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, static_cast (-1)); return this->cur_size_; } template ACE_INLINE size_t ACE_Map_Manager::total_size (void) const { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, static_cast (-1)); return this->total_size_; } template ACE_INLINE ACE_LOCK & ACE_Map_Manager::mutex (void) { return this->lock_; } template ACE_INLINE void ACE_Map_Manager::move_from_free_list_to_occupied_list (ACE_UINT32 slot) { this->shared_move (slot, this->free_list_, this->free_list_id (), this->occupied_list_, this->occupied_list_id ()); } template ACE_INLINE void ACE_Map_Manager::move_from_occupied_list_to_free_list (ACE_UINT32 slot) { this->shared_move (slot, this->occupied_list_, this->occupied_list_id (), this->free_list_, this->free_list_id ()); } template ACE_INLINE int ACE_Map_Manager::equal (const EXT_ID &id1, const EXT_ID &id2) { return id1 == id2; } template ACE_INLINE ACE_UINT32 ACE_Map_Manager::free_list_id (void) const { // If you change ~0, please change // ACE_Active_Map_Manager_Key::ACE_Active_Map_Manager_Key() // accordingly. return (ACE_UINT32) ~0; } template ACE_INLINE ACE_UINT32 ACE_Map_Manager::occupied_list_id (void) const { return (ACE_UINT32) ~1; } template ACE_INLINE ACE_Map_Iterator ACE_Map_Manager::begin (void) { return ACE_Map_Iterator (*this); } template ACE_INLINE ACE_Map_Iterator ACE_Map_Manager::end (void) { return ACE_Map_Iterator (*this, 1); } template ACE_INLINE ACE_Map_Reverse_Iterator ACE_Map_Manager::rbegin (void) { return ACE_Map_Reverse_Iterator (*this); } template ACE_INLINE ACE_Map_Reverse_Iterator ACE_Map_Manager::rend (void) { return ACE_Map_Reverse_Iterator (*this, 1); } template ACE_INLINE ACE_Map_Iterator_Base::ACE_Map_Iterator_Base (ACE_Map_Manager &mm) : map_man_ (&mm), next_ (this->map_man_->occupied_list_id ()) { } template ACE_INLINE int ACE_Map_Iterator_Base::next (ACE_Map_Entry *&mm) const { if (this->next_ != this->map_man_->occupied_list_id ()) { mm = &this->map_man_->search_structure_[this->next_]; return 1; } else return 0; } template ACE_INLINE int ACE_Map_Iterator_Base::done (void) const { return this->next_ == this->map_man_->occupied_list_id (); } template ACE_INLINE int ACE_Map_Iterator_Base::forward_i (void) { #if defined (ACE_HAS_LAZY_MAP_MANAGER) while (1) { // Go to the next item in the list. this->next_ = this->map_man_->search_structure_[this->next_].next (); // Stop if we reach the end. if (this->done ()) break; // Break if we find a non-free slot. if (!this->map_man_->search_structure_[this->next_].free_) { break; } } #else this->next_ = this->map_man_->search_structure_[this->next_].next (); #endif /* ACE_HAS_LAZY_MAP_MANAGER */ return this->next_ != this->map_man_->occupied_list_id (); } template ACE_INLINE int ACE_Map_Iterator_Base::reverse_i (void) { #if defined (ACE_HAS_LAZY_MAP_MANAGER) while (1) { // Go to the prev item in the list. this->next_ = this->map_man_->search_structure_[this->next_].prev (); // Stop if we reach the end. if (this->done ()) break; // Break if we find a non-free slot. if (!this->map_man_->search_structure_[this->next_].free_) { break; } } #else this->next_ = this->map_man_->search_structure_[this->next_].prev (); #endif /* ACE_HAS_LAZY_MAP_MANAGER */ return this->next_ != this->map_man_->occupied_list_id (); } template ACE_INLINE ACE_Map_Manager & ACE_Map_Iterator_Base::map (void) { return *this->map_man_; } template ACE_INLINE bool ACE_Map_Iterator_Base::operator== (const ACE_Map_Iterator_Base &rhs) const { return (this->map_man_ == rhs.map_man_ && this->next_ == rhs.next_); } template ACE_INLINE bool ACE_Map_Iterator_Base::operator!= (const ACE_Map_Iterator_Base &rhs) const { return !this->operator== (rhs); } template ACE_INLINE ACE_Map_Const_Iterator_Base::ACE_Map_Const_Iterator_Base (const ACE_Map_Manager &mm) : map_man_ (&mm), next_ (this->map_man_->occupied_list_id ()) { } template ACE_INLINE int ACE_Map_Const_Iterator_Base::next (ACE_Map_Entry *&mm) const { if (this->next_ != this->map_man_->occupied_list_id ()) { mm = &this->map_man_->search_structure_[this->next_]; return 1; } else return 0; } template ACE_INLINE int ACE_Map_Const_Iterator_Base::done (void) const { return this->next_ == this->map_man_->occupied_list_id (); } template ACE_INLINE int ACE_Map_Const_Iterator_Base::forward_i (void) { #if defined (ACE_HAS_LAZY_MAP_MANAGER) while (1) { // Go to the next item in the list. this->next_ = this->map_man_->search_structure_[this->next_].next (); // Stop if we reach the end. if (this->done ()) break; // Break if we find a non-free slot. if (!this->map_man_->search_structure_[this->next_].free_) { break; } } #else this->next_ = this->map_man_->search_structure_[this->next_].next (); #endif /* ACE_HAS_LAZY_MAP_MANAGER */ return this->next_ != this->map_man_->occupied_list_id (); } template ACE_INLINE int ACE_Map_Const_Iterator_Base::reverse_i (void) { #if defined (ACE_HAS_LAZY_MAP_MANAGER) while (1) { // Go to the prev item in the list. this->next_ = this->map_man_->search_structure_[this->next_].prev (); // Stop if we reach the end. if (this->done ()) break; // Break if we find a non-free slot. if (!this->map_man_->search_structure_[this->next_].free_) { break; } } #else this->next_ = this->map_man_->search_structure_[this->next_].prev (); #endif /* ACE_HAS_LAZY_MAP_MANAGER */ return this->next_ != this->map_man_->occupied_list_id (); } template ACE_INLINE const ACE_Map_Manager & ACE_Map_Const_Iterator_Base::map (void) const { return *this->map_man_; } template ACE_INLINE bool ACE_Map_Const_Iterator_Base::operator== (const ACE_Map_Const_Iterator_Base &rhs) const { return (this->map_man_ == rhs.map_man_ && this->next_ == rhs.next_); } template ACE_INLINE bool ACE_Map_Const_Iterator_Base::operator!= (const ACE_Map_Const_Iterator_Base &rhs) const { return !this->operator== (rhs); } template ACE_INLINE ACE_Map_Iterator::ACE_Map_Iterator (ACE_Map_Manager &mm, int pass_end) : ACE_Map_Iterator_Base (mm) { if (!pass_end) { #if defined (ACE_HAS_LAZY_MAP_MANAGER) // Start here. this->next_ = this->map_man_->occupied_list_.next (); while (1) { // Stop if we reach the end. if (this->done ()) break; // Break if we find a non-free slot. if (!this->map_man_->search_structure_[this->next_].free_) { break; } // Go to the next item in the list. this->next_ = this->map_man_->search_structure_[this->next_].next (); } #else this->next_ = this->map_man_->occupied_list_.next (); #endif /* ACE_HAS_LAZY_MAP_MANAGER */ } } template ACE_INLINE int ACE_Map_Iterator::advance (void) { return this->forward_i (); } template ACE_INLINE ACE_Map_Iterator & ACE_Map_Iterator::operator++ (void) { this->forward_i (); return *this; } template ACE_INLINE ACE_Map_Iterator ACE_Map_Iterator::operator++ (int) { ACE_Map_Iterator retv (*this); ++*this; return retv; } template ACE_INLINE ACE_Map_Iterator & ACE_Map_Iterator::operator-- (void) { this->reverse_i (); return *this; } template ACE_INLINE ACE_Map_Iterator ACE_Map_Iterator::operator-- (int) { ACE_Map_Iterator retv (*this); --*this; return retv; } template ACE_INLINE ACE_Map_Const_Iterator::ACE_Map_Const_Iterator (const ACE_Map_Manager &mm, int pass_end) : ACE_Map_Const_Iterator_Base (mm) { if (!pass_end) { #if defined (ACE_HAS_LAZY_MAP_MANAGER) // Start here. this->next_ = this->map_man_->occupied_list_.next (); while (1) { // Stop if we reach the end. if (this->done ()) break; // Break if we find a non-free slot. if (!this->map_man_->search_structure_[this->next_].free_) { break; } // Go to the next item in the list. this->next_ = this->map_man_->search_structure_[this->next_].next (); } #else this->next_ = this->map_man_->occupied_list_.next (); #endif /* ACE_HAS_LAZY_MAP_MANAGER */ } } template ACE_INLINE int ACE_Map_Const_Iterator::advance (void) { return this->forward_i (); } template ACE_INLINE ACE_Map_Const_Iterator & ACE_Map_Const_Iterator::operator++ (void) { this->forward_i (); return *this; } template ACE_INLINE ACE_Map_Const_Iterator ACE_Map_Const_Iterator::operator++ (int) { ACE_Map_Const_Iterator retv (*this); ++*this; return retv; } template ACE_INLINE ACE_Map_Const_Iterator & ACE_Map_Const_Iterator::operator-- (void) { this->reverse_i (); return *this; } template ACE_INLINE ACE_Map_Const_Iterator ACE_Map_Const_Iterator::operator-- (int) { ACE_Map_Const_Iterator retv (*this); --*this; return retv; } template ACE_INLINE ACE_Map_Reverse_Iterator::ACE_Map_Reverse_Iterator (ACE_Map_Manager &mm, int pass_end) : ACE_Map_Iterator_Base (mm) { if (!pass_end) { #if defined (ACE_HAS_LAZY_MAP_MANAGER) // Start here. this->next_ = this->map_man_->occupied_list_.prev (); while (1) { // Stop if we reach the end. if (this->done ()) break; // Break if we find a non-free slot. if (!this->map_man_->search_structure_[this->next_].free_) { break; } // Go to the prev item in the list. this->next_ = this->map_man_->search_structure_[this->next_].prev (); } #else this->next_ = this->map_man_->occupied_list_.prev (); #endif /* ACE_HAS_LAZY_MAP_MANAGER */ } } template ACE_INLINE int ACE_Map_Reverse_Iterator::advance (void) { return this->reverse_i (); } template ACE_INLINE ACE_Map_Reverse_Iterator & ACE_Map_Reverse_Iterator::operator++ (void) { this->reverse_i (); return *this; } template ACE_INLINE ACE_Map_Reverse_Iterator ACE_Map_Reverse_Iterator::operator++ (int) { ACE_Map_Reverse_Iterator retv (*this); ++*this; return retv; } template ACE_INLINE ACE_Map_Reverse_Iterator & ACE_Map_Reverse_Iterator::operator-- (void) { this->forward_i (); return *this; } template ACE_INLINE ACE_Map_Reverse_Iterator ACE_Map_Reverse_Iterator::operator-- (int) { ACE_Map_Reverse_Iterator retv (*this); --*this; return retv; } ACE_END_VERSIONED_NAMESPACE_DECL