#include <ObjectKey_Table.h>
Collaboration diagram for TAO::ObjectKey_Table:
Public Member Functions | |
ObjectKey_Table (void) | |
Default Constructor and destructor.. | |
~ObjectKey_Table (void) | |
int | init (TAO_ORB_Core *orb) |
int | destroy (void) |
Iterates and unbinds the contents of the table. | |
int | bind (const ObjectKey &key, Refcounted_ObjectKey *&key_new) |
Bind the ObjectKey in the table. | |
int | unbind (TAO::Refcounted_ObjectKey *&key) |
Unbind an ObjectKey from the table. | |
Protected Member Functions | |
int | bind_i (const ObjectKey &key, Refcounted_ObjectKey *&key_new) |
Implementation for bind (). | |
int | unbind_i (Refcounted_ObjectKey *&key) |
Implementation for unbind (). | |
Private Types | |
typedef ACE_RB_Tree< TAO::ObjectKey, TAO::Refcounted_ObjectKey *, TAO::Less_Than_ObjectKey, ACE_Null_Mutex > | TABLE |
Private Attributes | |
ACE_Lock * | lock_ |
Lock for the table. | |
TABLE | table_ |
Table that contains the data. |
The ORB maintains one table for the whole ORB. ObjectKeys generated by the ORB or the ones seen by the ORB from remote ORB's are stored here. The ObjectKeys are stored through a wrapper which encapsulates the refcount on them. This class actually provides the synchronization mechanism for manipulating the reference counts on the object keys provided by the wrapper class.
This class does not offer a find () call with a reason. The call to bind () will return a pointer which is expected to be cached by the client/caller and use the pointer in every invocation.
The reasons to use RB_Tree are its good dynamic properties. We should try to strategize the class to use either a Hash_Map or a RB_Tree based on some runtime option. For that we need an adapter class in ACE, like an ACE_Lock_Adapter class. We will do that if our instrumentation shows the need for it.
Definition at line 88 of file ObjectKey_Table.h.
typedef ACE_RB_Tree<TAO::ObjectKey, TAO::Refcounted_ObjectKey *, TAO::Less_Than_ObjectKey, ACE_Null_Mutex> TAO::ObjectKey_Table::TABLE [private] |
Definition at line 130 of file ObjectKey_Table.h.
TAO::ObjectKey_Table::ObjectKey_Table | ( | void | ) |
Default Constructor and destructor..
Definition at line 37 of file ObjectKey_Table.cpp.
References ObjectKey_Table().
Referenced by ObjectKey_Table().
TAO::ObjectKey_Table::~ObjectKey_Table | ( | void | ) |
Definition at line 44 of file ObjectKey_Table.cpp.
References ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::close(), lock_, table_, and ~ObjectKey_Table().
Referenced by ~ObjectKey_Table().
int TAO::ObjectKey_Table::bind | ( | const ObjectKey & | key, | |
Refcounted_ObjectKey *& | key_new | |||
) |
Bind the ObjectKey in the table.
Bind an ObjectKey in the table and return a pointer to the Refcounted_ObjectKey which the client can use. If the ObjectKey is already available in the table, this operation just increments the refcount on the ObjectKey. If the ObjectKey is new it is bounded to the table. Returns a 0 on success and a -1 on failure.
Definition at line 61 of file ObjectKey_Table.cpp.
References ACE_GUARD_RETURN, bind_i(), ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::find(), and table_.
00064 { 00065 key_new = 0; 00066 00067 int retval = 0; 00068 00069 { 00070 ACE_GUARD_RETURN (ACE_Lock, 00071 ace_mon, 00072 *this->lock_, 00073 0); 00074 00075 // This is a tradeoff.. We could avoid this two stage process of 00076 // using a find () and then a bind () , which would make things 00077 // efficient. BUT we may have to do allocation upfront and delete if 00078 // bind () returns with an entry. We take one of the routes that 00079 // avoids allocation. 00080 retval = this->table_.find (key, 00081 key_new); 00082 00083 if (retval == -1) 00084 { 00085 return this->bind_i (key, 00086 key_new); 00087 } 00088 00089 (void) key_new->incr_refcount (); 00090 } 00091 00092 return retval; 00093 }
int TAO::ObjectKey_Table::bind_i | ( | const ObjectKey & | key, | |
Refcounted_ObjectKey *& | key_new | |||
) | [protected] |
Implementation for bind ().
Definition at line 140 of file ObjectKey_Table.cpp.
References ACE_NEW_RETURN, ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::bind(), bind_i(), and table_.
Referenced by bind(), and bind_i().
00142 { 00143 ACE_NEW_RETURN (key_new, 00144 TAO::Refcounted_ObjectKey (key), 00145 -1); 00146 00147 int const retval = this->table_.bind (key, key_new); 00148 00149 if (retval != -1) 00150 { 00151 key_new->incr_refcount (); 00152 } 00153 else 00154 { 00155 key_new->decr_refcount (); 00156 } 00157 00158 return retval; 00159 }
int TAO::ObjectKey_Table::destroy | ( | void | ) |
Iterates and unbinds the contents of the table.
Definition at line 115 of file ObjectKey_Table.cpp.
References ACE_GUARD_RETURN, destroy(), ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::end(), table_, and ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::unbind().
Referenced by destroy().
00116 { 00117 if (this->table_.current_size ()) 00118 { 00119 ACE_GUARD_RETURN (ACE_Lock, 00120 ace_mon, 00121 *this->lock_, 00122 0); 00123 00124 TABLE::ITERATOR end_iter = this->table_.end (); 00125 TABLE::ITERATOR start; 00126 00127 while ((start = this->table_.begin ()) != end_iter) 00128 { 00129 TABLE::ENTRY &ent = (*start); 00130 00131 ent.item ()->decr_refcount (); 00132 this->table_.unbind (&ent); 00133 } 00134 } 00135 00136 return 0; 00137 }
int TAO::ObjectKey_Table::init | ( | TAO_ORB_Core * | orb | ) |
Initialize method that sets up the underlying lock and other related stuff.
Create the lock that is needed for internal usage.
Definition at line 51 of file ObjectKey_Table.cpp.
References TAO_Resource_Factory::create_object_key_table_lock(), lock_, and TAO_ORB_Core::resource_factory().
00052 { 00053 /// Create the lock that is needed for internal usage. 00054 this->lock_ = 00055 oc->resource_factory ()->create_object_key_table_lock (); 00056 00057 return 0; 00058 }
int TAO::ObjectKey_Table::unbind | ( | TAO::Refcounted_ObjectKey *& | key | ) |
Unbind an ObjectKey from the table.
Definition at line 96 of file ObjectKey_Table.cpp.
References ACE_GUARD_RETURN, and unbind().
Referenced by unbind().
00098 { 00099 ACE_GUARD_RETURN (ACE_Lock, 00100 ace_mon, 00101 *this->lock_, 00102 0); 00103 00104 // If the refcount has dropped to 1, just go ahead and unbind it 00105 // from the table. 00106 if (key_new && key_new->decr_refcount () == 1) 00107 { 00108 return this->unbind_i (key_new); 00109 } 00110 00111 return 0; 00112 }
int TAO::ObjectKey_Table::unbind_i | ( | Refcounted_ObjectKey *& | key | ) | [protected] |
Implementation for unbind ().
Definition at line 162 of file ObjectKey_Table.cpp.
References unbind_i().
Referenced by unbind_i().
00163 { 00164 TAO::Refcounted_ObjectKey *tmp = 0; 00165 00166 if (this->table_.unbind (key_new->object_key (), tmp) != -1) 00167 { 00168 // @@ Cant do much if the unbind fails. 00169 // Remove our refcount on the ObjectKey 00170 (void) tmp->decr_refcount (); 00171 } 00172 00173 return 0; 00174 }
ACE_Lock* TAO::ObjectKey_Table::lock_ [private] |
Lock for the table.
Definition at line 133 of file ObjectKey_Table.h.
Referenced by init(), and ~ObjectKey_Table().
TABLE TAO::ObjectKey_Table::table_ [private] |
Table that contains the data.
Definition at line 136 of file ObjectKey_Table.h.
Referenced by bind(), bind_i(), destroy(), and ~ObjectKey_Table().