summaryrefslogtreecommitdiff
path: root/TAO/tao/Transport_Cache_Manager.cpp
diff options
context:
space:
mode:
authoroci <oci@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2001-05-23 14:06:37 +0000
committeroci <oci@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2001-05-23 14:06:37 +0000
commit2a58065e41f0cee6169aed5eddce9b5c52962e63 (patch)
tree2f2f28af464a737f6dc5ee2a72d346c143e45fc5 /TAO/tao/Transport_Cache_Manager.cpp
parent05ab5ce28ae110eefc7453e8fa7807ebeef9ed32 (diff)
downloadATCD-2a58065e41f0cee6169aed5eddce9b5c52962e63.tar.gz
ChangeLogTag: Wed May 23 09:04:35 2001 Chad Elliott <elliott_c@ociweb.com>
Diffstat (limited to 'TAO/tao/Transport_Cache_Manager.cpp')
-rw-r--r--TAO/tao/Transport_Cache_Manager.cpp131
1 files changed, 61 insertions, 70 deletions
diff --git a/TAO/tao/Transport_Cache_Manager.cpp b/TAO/tao/Transport_Cache_Manager.cpp
index 5aa2c4dc086..8056d2f26b1 100644
--- a/TAO/tao/Transport_Cache_Manager.cpp
+++ b/TAO/tao/Transport_Cache_Manager.cpp
@@ -66,14 +66,22 @@ TAO_Transport_Cache_Manager::open (TAO_ORB_Core *orb_core,
int
TAO_Transport_Cache_Manager::bind_i (TAO_Cache_ExtId &ext_id,
- TAO_Cache_IntId &int_id)
+ TAO_Cache_IntId &int_id)
{
+ if (TAO_debug_level > 0)
+ {
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ")
+ ACE_TEXT ("TAO_Transport_Cache_Manager")
+ ACE_TEXT ("::bind_i (0x%x, 0x%x)\n"),
+ ext_id.property (), int_id.transport ()));
+ }
+
// 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);
+ this->purging_strategy_->update_item (int_id.transport ());
// When it comes for bind we know the transport is going to be busy
// and is marked for a partcular thread. So, mark it busy
@@ -143,11 +151,6 @@ TAO_Transport_Cache_Manager::find_transport (
int_id);
if (retval == 0)
{
- // Update the purging strategy information by unbinding
- // and then binding
- this->unbind (ext_id);
- this->bind (ext_id, int_id);
-
transport = int_id.relinquish_transport ();
}
@@ -241,9 +244,6 @@ TAO_Transport_Cache_Manager::unbind_i (const TAO_Cache_ExtId &key,
int
TAO_Transport_Cache_Manager::make_idle_i (HASH_MAP_ENTRY *&entry)
{
- if (entry == 0)
- return -1;
-
// First get the entry again (if at all things had changed in the
// cache map in the mean time)
HASH_MAP_ENTRY *new_entry = 0;
@@ -390,32 +390,34 @@ 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;
- if ((*left)->int_id_.purging_order () > (*right)->int_id_.purging_order ())
- return 1;
-
- if ((*left)->int_id_.purging_order () < (*right)->int_id_.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 ())
+ return 1;
+
return 0;
}
#endif /* ACE_LACKS_QSORT */
void
-TAO_Transport_Cache_Manager::sort_set (HASH_MAP_ENTRY**& entries,
+TAO_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_.purging_order () <
- entries[i - 1]->int_id_.purging_order ())
+ 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_.purging_order () >
- entry->int_id_.purging_order (); j--)
+ 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];
@@ -433,14 +435,16 @@ TAO_Transport_Cache_Manager::sort_set (HASH_MAP_ENTRY**& entries,
int
TAO_Transport_Cache_Manager::fill_set_i (DESCRIPTOR_SET& sorted_set)
{
- int amount = -1;
+ 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;
+
// Do we need to worry about cache purging?
if (cache_maximum >= 0)
{
- int current_size = this->cache_map_.current_size ();
- amount = current_size - cache_maximum;
+ current_size = this->cache_map_.current_size ();
if (TAO_debug_level > 0)
{
@@ -450,44 +454,29 @@ TAO_Transport_Cache_Manager::fill_set_i (DESCRIPTOR_SET& sorted_set)
current_size, cache_maximum));
}
- if (amount >= 0)
+ if (current_size >= cache_maximum)
{
- // I could not use ACE_Array_Base<HASH_MAP_ENTRY*> because
- // the compiler kept complaining about HASH_MAP_ENTRY not having
- // a default construtor.
- HASH_MAP_ENTRY** entries;
- ACE_NEW_RETURN(entries, HASH_MAP_ENTRY*[current_size], 0);
- sorted_set.size (current_size);
-
- int i;
+ ACE_NEW_RETURN (sorted_set, HASH_MAP_ENTRY*[current_size], 0);
+
HASH_MAP_ITER iter = this->cache_map_.begin ();
- for (i = 0; i < current_size; i++)
+ for (int i = 0; i < current_size; i++)
{
- entries[i] = &(*iter);
+ sorted_set[i] = &(*iter);
iter++;
}
-
- this->sort_set (entries, current_size);
-
- for(i = 0; i < current_size; i++)
- {
- // The owner of the sorted_set array accepts responsibility
- // for deleting the memory allocated here.
- sorted_set[i] = entries[i]->ext_id_.property ()->duplicate ();
- }
-
- delete [] entries;
+ this->sort_set (sorted_set, current_size);
}
}
- return (amount >= 0);
+ return current_size;
}
void
-TAO_Transport_Cache_Manager::close_entries(DESCRIPTOR_SET& sorted_set)
+TAO_Transport_Cache_Manager::close_entries(DESCRIPTOR_SET& sorted_set,
+ int sorted_size)
{
- const int sorted_size = sorted_set.size ();
+ // Calculate the number of entries to purge
const int amount = (sorted_size * this->percent_) / 100;
if (TAO_debug_level > 0)
@@ -499,33 +488,37 @@ TAO_Transport_Cache_Manager::close_entries(DESCRIPTOR_SET& sorted_set)
}
int count = 0;
- for(int i = 0; i < sorted_size; i++)
+ for(int i = 0; count < amount && i < sorted_size; i++)
{
- TAO_Transport_Descriptor_Interface* prop = sorted_set[i];
- if (count < amount)
+ if (this->is_entry_idle(sorted_set[i]))
{
- // Compose the ExternId
- TAO_Cache_ExtId ext_id (prop);
- TAO_Cache_IntId int_id;
-
- if (this->find (ext_id, int_id) == 0)
+ TAO_Transport* transport = sorted_set[i]->int_id_.transport ();
+ if (TAO_debug_level > 0)
{
- TAO_Transport* transport = int_id.relinquish_transport ();
- if (TAO_debug_level > 0)
- {
- ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ")
- ACE_TEXT ("Idle transport found in ")
- ACE_TEXT ("cache: 0x%x\n"),
- transport));
- }
-
- // Eventually calls purge_entry() on us.
- transport->close_connection ();
- count++;
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ")
+ ACE_TEXT ("Idle transport found in ")
+ ACE_TEXT ("cache: 0x%x\n"),
+ transport));
}
+
+ // We need to save the cache_map_entry before we
+ // set it to zero, so we can call purge_entry_i()
+ // after we call close_connection_i().
+ HASH_MAP_ENTRY* entry = transport->cache_map_entry ();
+
+ // This is a bit ugly, but we must do this to
+ // avoid taking and giving locks inside this loop.
+ transport->cache_map_entry (0);
+ transport->close_connection_i ();
+ this->purge_entry_i (entry);
+
+ // Count this as a successful purged entry
+ count++;
}
- delete prop;
}
+
+ delete [] sorted_set;
+ sorted_set = 0;
}
@@ -545,7 +538,6 @@ template class ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Cache_ExtId, TAO_Cache_IntId
template class ACE_Unbounded_Set<ACE_Event_Handler*>;
template class ACE_Unbounded_Set_Iterator<ACE_Event_Handler*>;
template class ACE_Node<ACE_Event_Handler*>;
-template class ACE_Array_Base<TAO_Transport_Descriptor_Interface*>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
@@ -563,6 +555,5 @@ template class ACE_Array_Base<TAO_Transport_Descriptor_Interface*>;
#pragma instantiate ACE_Unbounded_Set<ACE_Event_Handler*>
#pragma instantiate ACE_Unbounded_Set_Iterator<ACE_Event_Handler*>
#pragma instantiate ACE_Node<ACE_Event_Handler*>
-#pragma instantiate ACE_Array_Base<TAO_Transport_Descriptor_Interface*>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */