summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOssama Othman <ossama-othman@users.noreply.github.com>2002-03-16 10:05:58 +0000
committerOssama Othman <ossama-othman@users.noreply.github.com>2002-03-16 10:05:58 +0000
commit70f3b7f5913f8327362151ffef8d20309e68105e (patch)
treeb710577ef03df134bb988b044d9dcdc783d0c84f
parent69318e67ba2132c3b66d26aaa2cd2812b78d9b2f (diff)
downloadATCD-70f3b7f5913f8327362151ffef8d20309e68105e.tar.gz
ChangeLogTag:Sat Mar 16 00:47:58 2002 Ossama Othman <ossama@uci.edu>
-rw-r--r--TAO/ChangeLogs/ChangeLog-02a34
-rw-r--r--TAO/tao/Object.cpp59
-rw-r--r--TAO/tao/Object.h43
-rw-r--r--TAO/tao/Object.i4
4 files changed, 96 insertions, 44 deletions
diff --git a/TAO/ChangeLogs/ChangeLog-02a b/TAO/ChangeLogs/ChangeLog-02a
index 91caaacaa6d..65a4b020a61 100644
--- a/TAO/ChangeLogs/ChangeLog-02a
+++ b/TAO/ChangeLogs/ChangeLog-02a
@@ -1,3 +1,37 @@
+Sat Mar 16 00:47:58 2002 Ossama Othman <ossama@uci.edu>
+
+ * tao/Object.h (refcount_):
+
+ The CORBA::Object implementation will once again retain its own
+ reference count.
+
+ (refcount_lock_):
+
+ The reference count lock member is now instantiated on the
+ heap. It will only be instantiated if the object is an
+ unconstrained object (as opposed to locality-constrained). This
+ retains the same proven reference count semantics that existed
+ prior to the object reference instantiation optimization changes
+ from Wed Mar 6 21:55:11 2002 Ossama Othman <ossama@uci.edu>,
+ and simultaneously retains the optimization without the subtle
+ reference count issues incurred by coupling the object reference
+ reference count with the TAO_Stub reference count.
+
+ * tao/Object.i (CORBA_Object):
+ * tao/Object.cpp (CORBA_Object):
+
+ Initialize the reference count to one, and the reference count
+ lock pointer to zero.
+
+ (_add_ref, _remove_ref):
+
+ If the reference count lock pointer is non-zero then, perform
+ the appropriate reference count manipulation.
+
+ (~CORBA_Object):
+
+ Deallocate the reference count lock instance.
+
Sat Mar 16 01:58:21 2002 Ossama Othman <ossama@uci.edu>
* tao/IFR_Client/IFR_BaseC.cpp:
diff --git a/TAO/tao/Object.cpp b/TAO/tao/Object.cpp
index 617ec8b2adf..cbf25d28427 100644
--- a/TAO/tao/Object.cpp
+++ b/TAO/tao/Object.cpp
@@ -33,20 +33,31 @@ CORBA_Object::~CORBA_Object (void)
{
if (this->protocol_proxy_)
(void) this->protocol_proxy_->_decr_refcnt ();
+
+ delete this->refcount_lock_;
}
-CORBA_Object::CORBA_Object (TAO_Stub *protocol_proxy,
+CORBA_Object::CORBA_Object (TAO_Stub * protocol_proxy,
CORBA::Boolean collocated,
- TAO_Abstract_ServantBase *servant)
+ TAO_Abstract_ServantBase * servant)
: is_collocated_ (collocated),
servant_ (servant),
is_local_ (protocol_proxy == 0 ? 1 : 0),
proxy_broker_ (0),
- protocol_proxy_ (protocol_proxy)
+ protocol_proxy_ (protocol_proxy),
+ refcount_ (1),
+ refcount_lock_ (0)
{
-
if (protocol_proxy != 0)
{
+ // Only instantiate a lock if the object is unconstrained.
+ // Locality-constrained objects have no-op reference counting by
+ // default. Furthermore locality-constrained objects may be
+ // instantiated in the critical path. Instantiating a lock for
+ // unconstrained objects alone optimizes instantiation of such
+ // locality-constrained objects.
+ ACE_NEW (this->refcount_lock_, TAO_SYNCH_MUTEX);
+
// If the object is collocated then set the broker using the
// factory otherwise use the remote proxy broker.
if (this->is_collocated_ &&
@@ -54,49 +65,35 @@ CORBA_Object::CORBA_Object (TAO_Stub *protocol_proxy,
this->proxy_broker_ = _TAO_collocation_Object_Proxy_Broker_Factory_function_pointer (this);
else
this->proxy_broker_ = the_tao_remote_object_proxy_broker ();
-
- // Make sure the underlying TAO_Stub object is not yanked out
- // from under us. This will bring the TAO_Stub reference count
- // up to at least 2.
- (void) protocol_proxy->_incr_refcnt ();
}
}
void
CORBA_Object::_add_ref (void)
{
- if (this->protocol_proxy_ != 0)
- (void) this->protocol_proxy_->_incr_refcnt ();
+ if (this->refcount_lock_ != 0)
+ {
+ ACE_GUARD (TAO_SYNCH_MUTEX, mon, *this->refcount_lock_);
+
+ this->refcount_++;
+ }
}
void
CORBA_Object::_remove_ref (void)
{
- // Hijack the lock and reference count of the underlying TAO_Stub
- // object.
- // @@ There may be a race condition here. We may have to put the
- // lock back into this class.
- if (this->protocol_proxy_ != 0)
+ if (this->refcount_lock_ != 0)
{
- TAO_Stub * stub;
+ {
+ ACE_GUARD (TAO_SYNCH_MUTEX, mon, *this->refcount_lock_);
- {
- ACE_GUARD (TAO_SYNCH_MUTEX,
- mon,
- this->protocol_proxy_->refcount_lock ());
+ this->refcount_--;
- CORBA::ULong & refcnt = this->protocol_proxy_->refcount ();
-
- refcnt--;
- if (refcnt != 0)
+ if (this->refcount_ != 0)
return;
-
- stub = this->protocol_proxy_;
- this->protocol_proxy_ = 0;
}
-
- stub->destroy ();
- delete this;
+
+ delete this;
}
}
diff --git a/TAO/tao/Object.h b/TAO/tao/Object.h
index 493cc717c5e..1adecfd7b61 100644
--- a/TAO/tao/Object.h
+++ b/TAO/tao/Object.h
@@ -209,28 +209,35 @@ public:
#endif /* __GNUC__ */
// Useful for template programming.
- // = Reference count managment.
+ /**
+ * @name Reference Count Managment
+ *
+ * These are the standard CORBA object reference count manipulations
+ * methods.
+ */
+ //@{
/// Increment the reference count.
virtual void _add_ref (void);
/// Decrement the reference count.
virtual void _remove_ref (void);
+ //@}
- // = TAO extensions
-
+ /// Constructor
CORBA_Object (TAO_Stub *p = 0,
CORBA::Boolean collocated = 0,
TAO_Abstract_ServantBase *servant = 0);
- /// get the underlying stub object
+ /// Get the underlying stub object.
virtual TAO_Stub *_stubobj (void) const;
- /// Sets the proxy broker.
+ /// Set the proxy broker.
virtual void _proxy_broker (TAO_Object_Proxy_Broker *proxy_broker);
- /// Gets the proxy broker.
+ /// Get the proxy broker.
virtual TAO_Object_Proxy_Broker *_proxy_broker (void);
+ //@}
protected:
@@ -255,11 +262,8 @@ protected:
/// Specify whether this is a local object or not.
CORBA::Boolean is_local_;
- /**
- * Pointer to the Proxy Broker i.e. the instance
- * that takes care of getting the right proxy
- * for performing a given call.
- */
+ /// Pointer to the Proxy Broker i.e. the instance that takes care of
+ /// getting the right proxy for performing a given call.
TAO_Object_Proxy_Broker *proxy_broker_;
private:
@@ -270,7 +274,22 @@ private:
* The protocol proxy is (potentially) shared among several
* CORBA_Objects
*/
- TAO_Stub *protocol_proxy_;
+ TAO_Stub * protocol_proxy_;
+
+ /// Number of outstanding references to this object.
+ CORBA::ULong refcount_;
+
+ /// Protect reference count manipulation from race conditions.
+ /**
+ * This lock is only instantiated for unconstrained objects. The
+ * reason for this is that locality-constrained objects that do not
+ * require reference counting (the default) may be instantiated in
+ * the critical path.
+ *
+ * @note This assumes that unconstrained objects will not be
+ * instantiated in the critical path.
+ */
+ TAO_SYNCH_MUTEX * refcount_lock_;
};
diff --git a/TAO/tao/Object.i b/TAO/tao/Object.i
index e635c63ad59..a940db1ba43 100644
--- a/TAO/tao/Object.i
+++ b/TAO/tao/Object.i
@@ -10,7 +10,9 @@ CORBA_Object::CORBA_Object (int)
servant_ (0),
is_local_ (1),
proxy_broker_ (0),
- protocol_proxy_ (0)
+ protocol_proxy_ (0),
+ refcount_ (1),
+ refcount_lock_ (0)
{
}