diff options
author | bala <bala@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-03-11 08:27:14 +0000 |
---|---|---|
committer | bala <bala@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-03-11 08:27:14 +0000 |
commit | 7ccabb4917003cf4addddaf57303a8afc4d9d898 (patch) | |
tree | 660078a62afe28c1e282c4e37f8ef96806408b62 /TAO/tao/Transport_Cache_Manager.cpp | |
parent | e83789870224f2b070b51806f21200a8c66e53b8 (diff) | |
download | ATCD-7ccabb4917003cf4addddaf57303a8afc4d9d898.tar.gz |
ChangeLogTag:Fri Mar 11 12:00:35 (IST) 2005 Balachandran Natarajan <bala@dre.vanderbilt.edu>
Diffstat (limited to 'TAO/tao/Transport_Cache_Manager.cpp')
-rw-r--r-- | TAO/tao/Transport_Cache_Manager.cpp | 1089 |
1 files changed, 547 insertions, 542 deletions
diff --git a/TAO/tao/Transport_Cache_Manager.cpp b/TAO/tao/Transport_Cache_Manager.cpp index dbeaa8552d3..3c81ae877e1 100644 --- a/TAO/tao/Transport_Cache_Manager.cpp +++ b/TAO/tao/Transport_Cache_Manager.cpp @@ -17,671 +17,676 @@ ACE_RCSID (tao, Transport_Cache_Manager, "$Id$") - -TAO_Transport_Cache_Manager::TAO_Transport_Cache_Manager (TAO_ORB_Core &orb_core) - : percent_ (orb_core.resource_factory ()->purge_percentage ()) - , purging_strategy_ (orb_core.resource_factory ()->create_purging_strategy ()) - , cache_map_ (orb_core.resource_factory ()->cache_maximum ()) - , condition_ (0) - , cache_lock_ (0) - , muxed_number_ (orb_core.resource_factory ()->max_muxed_connections ()) - , no_waiting_threads_ (0) - , last_entry_returned_ (0) -{ - if (orb_core.resource_factory ()->locked_transport_cache ()) - { - ACE_NEW (this->condition_, - TAO_Condition <TAO_SYNCH_MUTEX>); - - ACE_NEW (this->cache_lock_, - ACE_Lock_Adapter <TAO_SYNCH_MUTEX> (*this->condition_->mutex ())); - } - else - { - /// If the cache is not going to be locked then dont create a - /// condition variable. Make the <muxed_number_> to 0, else a - /// single thread could get into waiting mode - this->muxed_number_ = 0; - ACE_NEW (this->cache_lock_, - ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX>); - } -} - -TAO_Transport_Cache_Manager::~TAO_Transport_Cache_Manager (void) +namespace TAO { - // Wakeup all the waiting threads threads before we shutdown stuff - if (this->no_waiting_threads_) - { - this->condition_->broadcast (); - } - - // Delete the lock that we have - if (this->cache_lock_) - { - delete this->cache_lock_; - this->cache_lock_ = 0; - } + Transport_Cache_Manager::Transport_Cache_Manager (TAO_ORB_Core &orb_core) + : percent_ (orb_core.resource_factory ()->purge_percentage ()) + , purging_strategy_ (orb_core.resource_factory ()->create_purging_strategy ()) + , cache_map_ (orb_core.resource_factory ()->cache_maximum ()) + , condition_ (0) + , cache_lock_ (0) + , muxed_number_ (orb_core.resource_factory ()->max_muxed_connections ()) + , no_waiting_threads_ (0) + , last_entry_returned_ (0) + { + if (orb_core.resource_factory ()->locked_transport_cache ()) + { + ACE_NEW (this->condition_, + TAO_Condition <TAO_SYNCH_MUTEX>); - // Delete the purging strategy - if (this->purging_strategy_) - { - delete this->purging_strategy_; - this->purging_strategy_ = 0; - } + ACE_NEW (this->cache_lock_, + ACE_Lock_Adapter <TAO_SYNCH_MUTEX> (*this->condition_->mutex ())); + } + else + { + /// If the cache is not going to be locked then dont create a + /// condition variable. Make the <muxed_number_> to 0, else a + /// single thread could get into waiting mode + this->muxed_number_ = 0; + ACE_NEW (this->cache_lock_, + ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX>); + } + } - // Delete the condition variable - if (this->condition_) - { - delete this->condition_; - this->condition_ = 0; - } -} + Transport_Cache_Manager::~Transport_Cache_Manager (void) + { + // Wakeup all the waiting threads threads before we shutdown stuff + if (this->no_waiting_threads_) + { + this->condition_->broadcast (); + } + // Delete the lock that we have + if (this->cache_lock_) + { + delete this->cache_lock_; + this->cache_lock_ = 0; + } -int -TAO_Transport_Cache_Manager::bind_i (TAO_Cache_ExtId &ext_id, - TAO_Cache_IntId &int_id) -{ - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - Transport_Cache_Manager::bind_i, " - "0x%x -> 0x%x Transport[%d]\n", - ext_id.property (), - int_id.transport (), - int_id.transport ()->id ())); - } + // Delete the purging strategy + if (this->purging_strategy_) + { + delete this->purging_strategy_; + this->purging_strategy_ = 0; + } - // Get the entry too - HASH_MAP_ENTRY *entry = 0; + // Delete the condition variable + if (this->condition_) + { + delete this->condition_; + this->condition_ = 0; + } + } - // Update the purging strategy information while we - // are holding our lock - this->purging_strategy_->update_item (int_id.transport ()); - int retval = this->cache_map_.bind (ext_id, - int_id, - entry); - if (retval == 0) - { - // The entry has been added to cache succesfully - // Add the cache_map_entry to the transport - int_id.transport ()->cache_map_entry (entry); - } - else if (retval == 1) - { - if (TAO_debug_level > 4 && retval != 0) - { - ACE_DEBUG ((LM_DEBUG, + int + Transport_Cache_Manager::bind_i (Cache_ExtId &ext_id, + Cache_IntId &int_id) + { + if (TAO_debug_level > 0) + { + ACE_DEBUG ((LM_DEBUG, + "TAO (%P|%t) - Transport_Cache_Manager::bind_i, " + "0x%x -> 0x%x Transport[%d]\n", + ext_id.property (), + int_id.transport (), + int_id.transport ()->id ())); + } + + // Get the entry too + HASH_MAP_ENTRY *entry = 0; + + // Update the purging strategy information while we + // are holding our lock + this->purging_strategy_->update_item (int_id.transport ()); + + int retval = this->cache_map_.bind (ext_id, + int_id, + entry); + if (retval == 0) + { + // The entry has been added to cache succesfully + // Add the cache_map_entry to the transport + int_id.transport ()->cache_map_entry (entry); + } + else if (retval == 1) + { + if (TAO_debug_level > 4 && retval != 0) + { + ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - Transport_Cache_Manager::bind_i, " - "unable to bind in the first attempt. " - "Trying with a new index\n")); - } + "unable to bind in the first attempt. " + "Trying with a new index\n")); + } - // There was an entry like this before, so let us do some - // minor adjustments and rebind - retval = this->get_last_index_bind (ext_id, - int_id, - entry); - if (retval == 0) - { - int_id.transport ()->cache_map_entry (entry); - } - } + // There was an entry like this before, so let us do some + // minor adjustments and rebind + retval = this->get_last_index_bind (ext_id, + int_id, + entry); + if (retval == 0) + { + int_id.transport ()->cache_map_entry (entry); + } + } - if (TAO_debug_level > 5 && retval != 0) - { - ACE_ERROR ((LM_ERROR, - "TAO (%P|%t) - Transport_Cache_Manager::bind_i, " - "unable to bind\n")); - } - else if (TAO_debug_level > 3) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - Transport_Cache_Manager::bind_i, " - "size is [%d]\n", - this->current_size ())); - } + if (TAO_debug_level > 5 && retval != 0) + { + ACE_ERROR ((LM_ERROR, + "TAO (%P|%t) - Transport_Cache_Manager::bind_i, " + "unable to bind\n")); + } + else if (TAO_debug_level > 3) + { + ACE_DEBUG ((LM_DEBUG, + "TAO (%P|%t) - Transport_Cache_Manager::bind_i, " + "size is [%d]\n", + this->current_size ())); + } - return retval; -} + return retval; + } -int -TAO_Transport_Cache_Manager::find_transport ( + int + Transport_Cache_Manager::find_transport ( TAO_Transport_Descriptor_Interface *prop, TAO_Transport *&transport) -{ - if (prop == 0) - { - transport = 0; - return -1; - } + { + if (prop == 0) + { + transport = 0; + return -1; + } - // Compose the ExternId - TAO_Cache_ExtId ext_id (prop); - TAO_Cache_IntId int_id; + // Compose the ExternId + Cache_ExtId ext_id (prop); + Cache_IntId int_id; - int retval = this->find (ext_id, - int_id); - if (retval == 0) - { - transport = int_id.relinquish_transport (); - } + int retval = this->find (ext_id, + int_id); + if (retval == 0) + { + transport = int_id.relinquish_transport (); + } - return retval; -} + return retval; + } -int -TAO_Transport_Cache_Manager::find (const TAO_Cache_ExtId &key, - TAO_Cache_IntId &value) -{ - ACE_MT (ACE_GUARD_RETURN (ACE_Lock, - guard, - *this->cache_lock_, - -1)); + int + Transport_Cache_Manager::find (const Cache_ExtId &key, + Cache_IntId &value) + { + ACE_MT (ACE_GUARD_RETURN (ACE_Lock, + guard, + *this->cache_lock_, + -1)); - int status = this->find_i (key, - value); + int status = this->find_i (key, + value); - if (status == 0) - { - // Update the purging strategy information while we - // are holding our lock - this->purging_strategy_->update_item (value.transport ()); - } + if (status == 0) + { + // Update the purging strategy information while we + // are holding our lock + this->purging_strategy_->update_item (value.transport ()); + } - return status; -} + return status; + } -int -TAO_Transport_Cache_Manager::find_i (const TAO_Cache_ExtId &key, - TAO_Cache_IntId &value) -{ - HASH_MAP_ENTRY *entry = 0; + int + Transport_Cache_Manager::find_i (const Cache_ExtId &key, + Cache_IntId &value) + { + HASH_MAP_ENTRY *entry = 0; - // Get the entry from the Hash Map - int retval = 0; + // Get the entry from the Hash Map + int retval = 0; - // Make a temporary object. It does not do a copy. - TAO_Cache_ExtId tmp_key (key.property ()); + // Make a temporary object. It does not do a copy. + Cache_ExtId tmp_key (key.property ()); - while (retval == 0) - { - // Wait for a connection.. - this->wait_for_connection (tmp_key); + while (retval == 0) + { + // Wait for a connection.. + this->wait_for_connection (tmp_key); - // Look for an entry in the map - retval = this->cache_map_.find (tmp_key, - entry); + // Look for an entry in the map + retval = this->cache_map_.find (tmp_key, + entry); - // We have an entry in the map, check whether it is idle. - if (entry) - { - CORBA::Boolean idle = - this->is_entry_idle (entry); + // We have an entry in the map, check whether it is idle. + if (entry) + { + CORBA::Boolean idle = + this->is_entry_idle (entry); - if (idle) - { - // Successfully found a TAO_Transport. + if (idle) + { + // Successfully found a TAO_Transport. - entry->int_id_.recycle_state (ACE_RECYCLABLE_BUSY); + entry->int_id_.recycle_state (ENTRY_BUSY); - // NOTE: This assignment operator indirectly incurs two - // lock operations since it duplicates and releases - // TAO_Transport objects. - value = entry->int_id_; + // NOTE: This assignment operator indirectly incurs two + // lock operations since it duplicates and releases + // TAO_Transport objects. + value = entry->int_id_; - if (TAO_debug_level > 4) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - Transport_Cache_Manager::find_i, " - "index in find <%d> (Transport[%d])\n", - entry->ext_id_.index (), - value.transport ()->id () - )); - } + if (TAO_debug_level > 4) + { + ACE_DEBUG ((LM_DEBUG, + "TAO (%P|%t) - Transport_Cache_Manager::find_i, " + "index in find <%d> (Transport[%d])\n", + entry->ext_id_.index (), + value.transport ()->id () + )); + } - return 0; - } - } + return 0; + } + } - // Bump the index up - tmp_key.incr_index (); - } + // Bump the index up + tmp_key.incr_index (); + } - // If we are here then it is an error - if (TAO_debug_level > 4 && retval != 0) - { - ACE_ERROR ((LM_ERROR, - "TAO (%P|%t) - Transport_Cache_Manager::find_i, " - "unable to locate a free connection\n")); - } + // If we are here then it is an error + if (TAO_debug_level > 4 && retval != 0) + { + ACE_ERROR ((LM_ERROR, + "TAO (%P|%t) - Transport_Cache_Manager::find_i, " + "unable to locate a free connection\n")); + } - return retval; -} + return retval; + } -int -TAO_Transport_Cache_Manager::make_idle_i (HASH_MAP_ENTRY *&entry) -{ - if (entry == 0) - return -1; + int + Transport_Cache_Manager::make_idle_i (HASH_MAP_ENTRY *&entry) + { + if (entry == 0) + return -1; - entry->int_id_.recycle_state (ACE_RECYCLABLE_IDLE_AND_PURGABLE); + entry->int_id_.recycle_state (ENTRY_IDLE_AND_PURGABLE); - // Does any one need waking? - if (this->no_waiting_threads_) - { - // We returned this entry to the map - this->last_entry_returned_ = &entry->ext_id_; + // Does any one need waking? + if (this->no_waiting_threads_) + { + // We returned this entry to the map + this->last_entry_returned_ = &entry->ext_id_; - // Wake up a thread - this->condition_->signal (); - } + // Wake up a thread + this->condition_->signal (); + } - return 0; -} + return 0; + } -int -TAO_Transport_Cache_Manager::update_entry (HASH_MAP_ENTRY *&entry) -{ - if(entry == 0) - { + int + Transport_Cache_Manager::update_entry (HASH_MAP_ENTRY *&entry) + { + if(entry == 0) return -1; - } - ACE_MT (ACE_GUARD_RETURN (ACE_Lock, - guard, + ACE_MT (ACE_GUARD_RETURN (ACE_Lock, + guard, *this->cache_lock_, -1)); - if (entry == 0) - { + if (entry == 0) return -1; - } - TAO_Connection_Purging_Strategy *st = this->purging_strategy_; - (void) st->update_item (entry->int_id_.transport ()); + TAO_Connection_Purging_Strategy *st = this->purging_strategy_; + (void) st->update_item (entry->int_id_.transport ()); - return 0; -} - -int -TAO_Transport_Cache_Manager::close_i (TAO_Connection_Handler_Set &handlers) -{ - HASH_MAP_ITER end_iter = this->cache_map_.end (); - - for (HASH_MAP_ITER iter = this->cache_map_.begin (); - iter != end_iter; - ++iter) - { - // First we look through whether we have an entry that has already - // been closed. + return 0; + } - if ((*iter).int_id_.recycle_state () != ACE_RECYCLABLE_CLOSED) - { - // Get the transport to fill its associated connection's handler. - (*iter).int_id_.transport ()->provide_handler (handlers); - // Inform the transport that has a reference to the entry in the - // map that we are *gone* now. So, the transport should not use - // the reference to the entry that he has, to acces us *at any - // time*. - (*iter).int_id_.transport ()->cache_map_entry (0); - } - } + int + Transport_Cache_Manager::close_i (Connection_Handler_Set &handlers) + { + HASH_MAP_ITER end_iter = this->cache_map_.end (); - // Unbind all the entries in the map - this->cache_map_.unbind_all (); + for (HASH_MAP_ITER iter = this->cache_map_.begin (); + iter != end_iter; + ++iter) + { + // Get the transport to fill its associated connection's handler. + (*iter).int_id_.transport ()->provide_handler (handlers); - return 0; -} + // Inform the transport that has a reference to the entry in the + // map that we are *gone* now. So, the transport should not use + // the reference to the entry that he has, to acces us *at any + // time*. + (*iter).int_id_.transport ()->cache_map_entry (0); + } -int -TAO_Transport_Cache_Manager::purge_entry_i (HASH_MAP_ENTRY *&entry) -{ - if (entry == 0) - { - return 0; - } + // Unbind all the entries in the map + this->cache_map_.unbind_all (); - // Remove the entry from the Map - int retval = this->cache_map_.unbind (entry); + return 0; + } - // Set the entry pointer to zero - entry = 0; + bool + Transport_Cache_Manager::blockable_client_transports_i ( + Connection_Handler_Set &h) + { + HASH_MAP_ITER end_iter = this->cache_map_.end (); - return retval; -} + for (HASH_MAP_ITER iter = this->cache_map_.begin (); + iter != end_iter; + ++iter) + { + // Get the transport to fill its associated connection's + // handler. + (*iter).int_id_.transport ()->provide_blockable_handler (h); + (*iter).int_id_.recycle_state (ENTRY_CLOSED); + } -void -TAO_Transport_Cache_Manager::mark_invalid_i (HASH_MAP_ENTRY *&entry) -{ - if (entry == 0) - { - return; - } + return true; + } - // Mark the entry as not usable - entry->int_id_.recycle_state (ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE); -} + int + Transport_Cache_Manager::purge_entry_i (HASH_MAP_ENTRY *&entry) + { + if (entry == 0) + { + return 0; + } + // Remove the entry from the Map + int retval = this->cache_map_.unbind (entry); + // Set the entry pointer to zero + entry = 0; -int -TAO_Transport_Cache_Manager::get_last_index_bind (TAO_Cache_ExtId &key, - TAO_Cache_IntId &val, - HASH_MAP_ENTRY *&entry) -{ - CORBA::ULong ctr = entry->ext_id_.index (); - int retval = 0; + return retval; + } - while (retval == 0) - { - // Set the index - key.index (++ctr); + void + Transport_Cache_Manager::mark_invalid_i (HASH_MAP_ENTRY *&entry) + { + if (entry == 0) + { + return; + } - // Check to see if an element exists in the Map. If it exists we - // loop, else we drop out of the loop - retval = this->cache_map_.find (key); - } + // Mark the entry as not usable + entry->int_id_.recycle_state (ENTRY_PURGABLE_BUT_NOT_IDLE); + } - // Now do a bind again with the new index - return this->cache_map_.bind (key, - val, - entry); -} + int + Transport_Cache_Manager::get_last_index_bind (Cache_ExtId &key, + Cache_IntId &val, + HASH_MAP_ENTRY *&entry) + { + CORBA::ULong ctr = entry->ext_id_.index (); + int retval = 0; + while (retval == 0) + { + // Set the index + key.index (++ctr); + + // Check to see if an element exists in the Map. If it exists we + // loop, else we drop out of the loop + retval = this->cache_map_.find (key); + } + + // Now do a bind again with the new index + return this->cache_map_.bind (key, + val, + entry); + } -int -TAO_Transport_Cache_Manager::is_entry_idle (HASH_MAP_ENTRY *&entry) -{ - ACE_Recyclable_State recycle_state = entry->int_id_.recycle_state (); - if (TAO_debug_level) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - Transport_Cache_Manager::is_entry_idle, " - "state is [%d]\n", - recycle_state)); - } + bool + Transport_Cache_Manager::is_entry_idle (HASH_MAP_ENTRY *&entry) + { + Cache_Entries_State entry_state = + entry->int_id_.recycle_state (); - if (recycle_state == ACE_RECYCLABLE_IDLE_AND_PURGABLE || - recycle_state == ACE_RECYCLABLE_IDLE_BUT_NOT_PURGABLE) - { - return 1; - } + if (TAO_debug_level) + { + ACE_DEBUG ((LM_DEBUG, + "TAO (%P|%t) - Transport_Cache_Manager::is_entry_idle, " + "state is [%d]\n", + entry_state)); + } - return 0; -} + if (entry_state == ENTRY_IDLE_AND_PURGABLE || + entry_state == ENTRY_IDLE_BUT_NOT_PURGABLE) + return true; + return false; + } #if !defined (ACE_LACKS_QSORT) -int -TAO_Transport_Cache_Manager::cpscmp(const void* a, const void* b) -{ - const HASH_MAP_ENTRY** left = (const HASH_MAP_ENTRY**)a; - const HASH_MAP_ENTRY** right = (const HASH_MAP_ENTRY**)b; + int + Transport_Cache_Manager::cpscmp(const void* a, const void* b) + { + const HASH_MAP_ENTRY** left = (const HASH_MAP_ENTRY**)a; + const HASH_MAP_ENTRY** right = (const HASH_MAP_ENTRY**)b; - if ((*left)->int_id_.transport ()->purging_order () < - (*right)->int_id_.transport ()->purging_order ()) - { + if ((*left)->int_id_.transport ()->purging_order () < + (*right)->int_id_.transport ()->purging_order ()) return -1; - } - if ((*left)->int_id_.transport ()->purging_order () > - (*right)->int_id_.transport ()->purging_order ()) - { + if ((*left)->int_id_.transport ()->purging_order () > + (*right)->int_id_.transport ()->purging_order ()) return 1; - } - return 0; -} + return 0; + } #endif /* ACE_LACKS_QSORT */ -int -TAO_Transport_Cache_Manager::purge (void) -{ - ACE_Unbounded_Stack<TAO_Transport*> transports_to_be_closed; - + int + Transport_Cache_Manager::purge (void) { - ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->cache_lock_, 0)); - - DESCRIPTOR_SET sorted_set = 0; - int sorted_size = this->fill_set_i (sorted_set); + ACE_Unbounded_Stack<TAO_Transport*> transports_to_be_closed; - // Only call close_entries () if sorted_set != 0. It takes control of - // sorted_set and cleans up any allocated memory. If sorted_set == 0, - // then there is nothing to de-allocate. - if (sorted_set != 0) - { - // BEGIN FORMER close_entries - // Calculate the number of entries to purge - const int amount = (sorted_size * this->percent_) / 100; + { + ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->cache_lock_, 0)); - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager::") - ACE_TEXT ("purge, purging %d of %d cache entries\n"), - amount, - sorted_size)); - } + DESCRIPTOR_SET sorted_set = 0; + int sorted_size = this->fill_set_i (sorted_set); - int count = 0; + // Only call close_entries () if sorted_set != 0. It takes + // control of sorted_set and cleans up any allocated memory. If + // sorted_set == 0, then there is nothing to de-allocate. + if (sorted_set != 0) + { + // BEGIN FORMER close_entries + // Calculate the number of entries to purge + const int amount = (sorted_size * this->percent_) / 100; - for(int i = 0; count < amount && i < sorted_size; ++i) - { - if (this->is_entry_idle (sorted_set[i])) - { - sorted_set[i]->int_id_.recycle_state (ACE_RECYCLABLE_BUSY); + if (TAO_debug_level > 0) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager::") + ACE_TEXT ("purge, purging %d of %d cache entries\n"), + amount, + sorted_size)); + } - TAO_Transport* transport = - sorted_set[i]->int_id_.transport (); - transport->add_reference (); + int count = 0; - if (transports_to_be_closed.push (transport) != 0) - { - ACE_DEBUG ((LM_INFO, - ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("Unable to push transport %u ") - ACE_TEXT ("on the to-be-closed stack, so ") - ACE_TEXT ("it will leak\n"), + for (int i = 0; count < amount && i < sorted_size; ++i) + { + if (this->is_entry_idle (sorted_set[i])) + { + sorted_set[i]->int_id_.recycle_state (ENTRY_BUSY); + + TAO_Transport* transport = + sorted_set[i]->int_id_.transport (); + transport->add_reference (); + + if (transports_to_be_closed.push (transport) != 0) + { + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("Unable to push transport %u ") + ACE_TEXT ("on the to-be-closed stack, so ") + ACE_TEXT ("it will leak\n"), transport->id ())); - } + } + + if (TAO_debug_level > 0) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("Idle transport found in ") + ACE_TEXT ("cache: [%d] \n"), + transport->id ())); + } + + // Count this as a successful purged entry + count++; + } + } - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("Idle transport found in ") - ACE_TEXT ("cache: [%d] \n"), - transport->id ())); - } + delete [] sorted_set; + sorted_set = 0; + // END FORMER close_entries + } + } + + // Now, without the lock held, lets go through and close all the transports. + TAO_Transport *transport = 0; - // Count this as a successful purged entry - count++; + while (! transports_to_be_closed.is_empty ()) + { + if (transports_to_be_closed.pop (transport) == 0) + { + if (transport) + { + transport->close_connection (); + transport->remove_reference (); } } + } - delete [] sorted_set; - sorted_set = 0; - // END FORMER close_entries - } + return 0; } - // Now, without the lock held, lets go through and close all the transports. - TAO_Transport *transport = 0; - - while (! transports_to_be_closed.is_empty ()) - { - if (transports_to_be_closed.pop (transport) == 0) - { - if (transport) - { - transport->close_connection (); - transport->remove_reference (); - } - } - } - - return 0; -} - -void -TAO_Transport_Cache_Manager::sort_set (DESCRIPTOR_SET& entries, - int current_size) -{ + void + Transport_Cache_Manager::sort_set (DESCRIPTOR_SET& entries, + int current_size) + { #if defined (ACE_LACKS_QSORT) - // Use insertion sort if we don't have qsort - for(int i = 1; i < current_size; ++i) - { - if (entries[i]->int_id_.transport ()->purging_order () < - entries[i - 1]->int_id_.transport ()->purging_order ()) - { - HASH_MAP_ENTRY* entry = entries[i]; + // Use insertion sort if we don't have qsort + for(int i = 1; i < current_size; ++i) + { + if (entries[i]->int_id_.transport ()->purging_order () < + entries[i - 1]->int_id_.transport ()->purging_order ()) + { + HASH_MAP_ENTRY* entry = entries[i]; - for(int j = i; j > 0 && - entries[j - 1]->int_id_.transport ()->purging_order () > - entry->int_id_.transport ()->purging_order (); --j) - { - HASH_MAP_ENTRY* holder = entries[j]; - entries[j] = entries[j - 1]; - entries[j - 1] = holder; - } - } - } + for(int j = i; j > 0 && + entries[j - 1]->int_id_.transport ()->purging_order () > + entry->int_id_.transport ()->purging_order (); --j) + { + HASH_MAP_ENTRY* holder = entries[j]; + entries[j] = entries[j - 1]; + entries[j - 1] = holder; + } + } + } #else - ACE_OS::qsort (entries, current_size, - sizeof (HASH_MAP_ENTRY*), (ACE_COMPARE_FUNC)cpscmp); + ACE_OS::qsort (entries, current_size, + sizeof (HASH_MAP_ENTRY*), (ACE_COMPARE_FUNC)cpscmp); #endif /* ACE_LACKS_QSORT */ -} + } -int -TAO_Transport_Cache_Manager::fill_set_i (DESCRIPTOR_SET& sorted_set) -{ - int current_size = 0; - int cache_maximum = this->purging_strategy_->cache_maximum (); + int + Transport_Cache_Manager::fill_set_i (DESCRIPTOR_SET& sorted_set) + { + int current_size = 0; + int cache_maximum = this->purging_strategy_->cache_maximum (); - // set sorted_set to 0. This signifies nothing to purge. - sorted_set = 0; + // set sorted_set to 0. This signifies nothing to purge. + sorted_set = 0; - // Do we need to worry about cache purging? - if (cache_maximum >= 0) - { - current_size = static_cast<int> (this->cache_map_.current_size ()); + // Do we need to worry about cache purging? + if (cache_maximum >= 0) + { + current_size = static_cast<int> (this->cache_map_.current_size ()); - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - Transport_Cache_Manager::fill_set_i, " - "current_size = %d, cache_maximum = %d\n", - current_size, cache_maximum)); - } + if (TAO_debug_level > 0) + { + ACE_DEBUG ((LM_DEBUG, + "TAO (%P|%t) - Transport_Cache_Manager::fill_set_i, " + "current_size = %d, cache_maximum = %d\n", + current_size, cache_maximum)); + } - if (current_size >= cache_maximum) - { - ACE_NEW_RETURN (sorted_set, HASH_MAP_ENTRY*[current_size], 0); + if (current_size >= cache_maximum) + { + ACE_NEW_RETURN (sorted_set, HASH_MAP_ENTRY*[current_size], 0); - HASH_MAP_ITER iter = this->cache_map_.begin (); + HASH_MAP_ITER iter = this->cache_map_.begin (); - for (int i = 0; i < current_size; ++i) - { - sorted_set[i] = &(*iter); - iter++; - } + for (int i = 0; i < current_size; ++i) + { + sorted_set[i] = &(*iter); + iter++; + } - this->sort_set (sorted_set, current_size); - } + this->sort_set (sorted_set, current_size); + } } - return current_size; -} + return current_size; + } -int -TAO_Transport_Cache_Manager::wait_for_connection (TAO_Cache_ExtId &extid) -{ - if (this->muxed_number_ && this->muxed_number_ == extid.index ()) - { - // If we have a limit on the number of muxed connections for - // a particular endpoint just wait to get the connection - ++this->no_waiting_threads_; + int + Transport_Cache_Manager::wait_for_connection (Cache_ExtId &extid) + { + if (this->muxed_number_ && this->muxed_number_ == extid.index ()) + { + // If we have a limit on the number of muxed connections for + // a particular endpoint just wait to get the connection + ++this->no_waiting_threads_; - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - Transport_Cache_Manager" - "::wait_for_connection, " - "entering wait loop\n")); - } + if (TAO_debug_level > 2) + { + ACE_DEBUG ((LM_DEBUG, + "TAO (%P|%t) - Transport_Cache_Manager" + "::wait_for_connection, " + "entering wait loop\n")); + } - int ready_togo = 0; + int ready_togo = 0; - while (ready_togo == 0) - { - this->condition_->wait (); + while (ready_togo == 0) + { + this->condition_->wait (); - // Check whether we are waiting for this connection - ready_togo = this->is_wakeup_useful (extid); - } + // Check whether we are waiting for this connection + ready_togo = this->is_wakeup_useful (extid); + } - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - Transport_Cache_Manager::wait_for_connection, " + if (TAO_debug_level > 2) + { + ACE_DEBUG ((LM_DEBUG, + "TAO (%P|%t) - Transport_Cache_Manager::wait_for_connection, " "left wait loop\n")); - } + } - // We are not waiting anymore - --this->no_waiting_threads_; - } + // We are not waiting anymore + --this->no_waiting_threads_; + } - return 0; -} + return 0; + } -int -TAO_Transport_Cache_Manager::is_wakeup_useful (TAO_Cache_ExtId &extid) -{ - // Get the underlying property that we are looking for - TAO_Transport_Descriptor_Interface *prop = extid.property (); - - // Just check the underlying property for equivalence. If the last - // connection that was returned had the same property just return - // 1. - if (this->last_entry_returned_ && - prop->is_equivalent (this->last_entry_returned_->property ())) - { - // Set the index to be right so that we can pick teh connection - // right away.. - extid.index (this->last_entry_returned_->index ()); + int + Transport_Cache_Manager::is_wakeup_useful (Cache_ExtId &extid) + { + // Get the underlying property that we are looking for + TAO_Transport_Descriptor_Interface *prop = extid.property (); + + // Just check the underlying property for equivalence. If the last + // connection that was returned had the same property just return + // 1. + if (this->last_entry_returned_ && + prop->is_equivalent (this->last_entry_returned_->property ())) + { + // Set the index to be right so that we can pick teh connection + // right away.. + extid.index (this->last_entry_returned_->index ()); - // There is no more use for it ... - this->last_entry_returned_ = 0; + // There is no more use for it ... + this->last_entry_returned_ = 0; - return 1; - } + return 1; + } - // If there is an entry that was returned and if there are more - // threads just wake up the peer to check for the returned - // connection. - if (this->last_entry_returned_ && - this->no_waiting_threads_ > 1) - { - this->condition_->signal (); - } + // If there is an entry that was returned and if there are more + // threads just wake up the peer to check for the returned + // connection. + if (this->last_entry_returned_ && + this->no_waiting_threads_ > 1) + { + this->condition_->signal (); + } + + return 0; + } - return 0; } #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) // Instantiations for the Hash Map -template class ACE_Equal_To<TAO_Cache_ExtId>; -template class ACE_Hash<TAO_Cache_ExtId>; -template class ACE_Hash_Map_Entry<TAO_Cache_ExtId, TAO_Cache_IntId>; -template class ACE_Hash_Map_Manager_Ex<TAO_Cache_ExtId, TAO_Cache_IntId, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>; -template class ACE_Hash_Map_Iterator_Base_Ex<TAO_Cache_ExtId, TAO_Cache_IntId, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>; -template class ACE_Hash_Map_Iterator_Ex<TAO_Cache_ExtId, TAO_Cache_IntId, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>; -template class ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Cache_ExtId, TAO_Cache_IntId, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>; +template class ACE_Equal_To<Cache_ExtId>; +template class ACE_Hash<Cache_ExtId>; +template class ACE_Hash_Map_Entry<Cache_ExtId, Cache_IntId>; +template class ACE_Hash_Map_Manager_Ex<Cache_ExtId, Cache_IntId, ACE_Hash<Cache_ExtId>, ACE_Equal_To<Cache_ExtId>, ACE_Null_Mutex>; +template class ACE_Hash_Map_Iterator_Base_Ex<Cache_ExtId, Cache_IntId, ACE_Hash<Cache_ExtId>, ACE_Equal_To<Cache_ExtId>, ACE_Null_Mutex>; +template class ACE_Hash_Map_Iterator_Ex<Cache_ExtId, Cache_IntId, ACE_Hash<Cache_ExtId>, ACE_Equal_To<Cache_ExtId>, ACE_Null_Mutex>; +template class ACE_Hash_Map_Reverse_Iterator_Ex<Cache_ExtId, Cache_IntId, ACE_Hash<Cache_ExtId>, ACE_Equal_To<Cache_ExtId>, ACE_Null_Mutex>; template class ACE_Unbounded_Set<TAO_Connection_Handler*>; template class ACE_Unbounded_Set_Iterator<TAO_Connection_Handler*>; template class ACE_Node<TAO_Connection_Handler*>; @@ -692,13 +697,13 @@ template class TAO_Condition<ACE_SYNCH_MUTEX>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) // Instantiations for the Hash Map -#pragma instantiate ACE_Equal_To<TAO_Cache_ExtId> -#pragma instantiate ACE_Hash<TAO_Cache_ExtId> -#pragma instantiate ACE_Hash_Map_Entry<TAO_Cache_ExtId, TAO_Cache_IntId> -#pragma instantiate ACE_Hash_Map_Manager_Ex<TAO_Cache_ExtId, TAO_Cache_IntId, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<TAO_Cache_ExtId, TAO_Cache_IntId, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Iterator_Ex<TAO_Cache_ExtId, TAO_Cache_IntId, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Cache_ExtId, TAO_Cache_IntId, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex> +#pragma instantiate ACE_Equal_To<Cache_ExtId> +#pragma instantiate ACE_Hash<Cache_ExtId> +#pragma instantiate ACE_Hash_Map_Entry<Cache_ExtId, Cache_IntId> +#pragma instantiate ACE_Hash_Map_Manager_Ex<Cache_ExtId, Cache_IntId, ACE_Hash<Cache_ExtId>, ACE_Equal_To<Cache_ExtId>, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<Cache_ExtId, Cache_IntId, ACE_Hash<Cache_ExtId>, ACE_Equal_To<Cache_ExtId>, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Iterator_Ex<Cache_ExtId, Cache_IntId, ACE_Hash<Cache_ExtId>, ACE_Equal_To<Cache_ExtId>, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<Cache_ExtId, Cache_IntId, ACE_Hash<Cache_ExtId>, ACE_Equal_To<Cache_ExtId>, ACE_Null_Mutex> #pragma instantiate ACE_Unbounded_Set<TAO_Connection_Handler*> #pragma instantiate ACE_Unbounded_Set_Iterator<TAO_Connection_Handler*> #pragma instantiate ACE_Node<TAO_Connection_Handler*> |