Skip to content

Commit

Permalink
Experiment with std::once_call
Browse files Browse the repository at this point in the history
    * TAO/TAO_IDL/be/be_visitor_operation/ami_cs.cpp:
    * TAO/TAO_IDL/be/be_visitor_operation/operation.cpp:
    * TAO/tao/Object.cpp:
    * TAO/tao/Object.h:
    * TAO/tao/Object.inl:
  • Loading branch information
jwillemsen committed Jun 27, 2024
1 parent ad3dd2c commit b00bd29
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 69 deletions.
6 changes: 1 addition & 5 deletions TAO/TAO_IDL/be/be_visitor_operation/ami_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ be_visitor_operation_ami_cs::visit_operation (be_operation *node)
else
{
*os << be_nl
<< "if (!this->is_evaluated ())" << be_idt_nl
<< "{" << be_idt_nl
<< "::CORBA::Object::tao_object_initialize (this);"
<< be_uidt_nl
<< "}" << be_uidt_nl << be_nl;
<< "std::call_once(this->object_initialized_flag_, CORBA::Object::tao_object_initialize, this);" << be_nl_2;
}

// Includes the reply handler, but we have to add 1 for the retval anyway.
Expand Down
8 changes: 2 additions & 6 deletions TAO/TAO_IDL/be/be_visitor_operation/operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,8 @@ be_visitor_operation::gen_stub_operation_body (
if (!node->is_abstract ())
{
// If the object is lazily evaluated the proxy broker might well
// be null. Initialize it now.
*os << "if (!this->is_evaluated ())" << be_idt_nl
<< "{" << be_idt_nl
<< "::CORBA::Object::tao_object_initialize (this);"
<< be_uidt_nl
<< "}" << be_uidt_nl << be_nl;
// be null. Initialize it now.
*os << "std::call_once(this->object_initialized_flag_, CORBA::Object::tao_object_initialize, this);" << be_nl_2;
}

// Declare return type helper class.
Expand Down
60 changes: 24 additions & 36 deletions TAO/tao/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ CORBA::Object::Object (TAO_Stub * protocol_proxy,
TAO_ORB_Core *orb_core)
: refcount_ (1)
, is_local_ (false)
, is_evaluated_ (true)
, ior_ (nullptr)
, orb_core_ (orb_core)
, protocol_proxy_ (protocol_proxy)
Expand All @@ -67,7 +66,6 @@ CORBA::Object::Object (IOP::IOR *ior,
TAO_ORB_Core *orb_core)
: refcount_ (1)
, is_local_ (false)
, is_evaluated_ (false)
, ior_ (ior)
, orb_core_ (orb_core)
, protocol_proxy_ (nullptr)
Expand All @@ -77,20 +75,7 @@ CORBA::Object::Object (IOP::IOR *ior,
// Too lazy to do this check in every method properly! This is useful
// only for lazily evaluated IOR's
#define TAO_OBJECT_IOR_EVALUATE \
if (!this->is_evaluated_) \
{ \
ACE_GUARD (TAO_SYNCH_MUTEX , mon, this->object_init_lock_); \
if (!this->is_evaluated_) \
CORBA::Object::tao_object_initialize (this); \
}

#define TAO_OBJECT_IOR_EVALUATE_RETURN \
if (!this->is_evaluated_) \
{ \
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX , mon, this->object_init_lock_, 0); \
if (!this->is_evaluated_) \
CORBA::Object::tao_object_initialize (this); \
}
std::call_once(this->object_initialized_flag_, CORBA::Object::tao_object_initialize, this);

void
CORBA::Object::_add_ref ()
Expand Down Expand Up @@ -190,7 +175,7 @@ CORBA::Object::_servant () const
CORBA::Boolean
CORBA::Object::_is_a (const char *type_id)
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;

// NOTE: if _stub->type_id is nonzero and we have local knowledge of
// it, we can answer this question without a costly remote call.
Expand Down Expand Up @@ -258,14 +243,14 @@ CORBA::Object::_stubobj () const
TAO_Stub *
CORBA::Object::_stubobj ()
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;
return this->protocol_proxy_;
}

CORBA::ULong
CORBA::Object::_hash (CORBA::ULong maximum)
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;

if (this->protocol_proxy_ != nullptr)
return this->protocol_proxy_->hash (maximum);
Expand Down Expand Up @@ -297,7 +282,7 @@ CORBA::Object::_is_equivalent (CORBA::Object_ptr other_obj)
return true;
}

TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;

if (this->protocol_proxy_ != nullptr)
return this->protocol_proxy_->is_equivalent (other_obj);
Expand All @@ -310,7 +295,7 @@ CORBA::Object::_is_equivalent (CORBA::Object_ptr other_obj)
TAO::ObjectKey *
CORBA::Object::_key ()
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;

if (this->_stubobj () && this->_stubobj ()->profile_in_use ())
return this->_stubobj ()->profile_in_use ()->_key ();
Expand Down Expand Up @@ -444,7 +429,7 @@ CORBA::Object::_create_request (CORBA::Context_ptr ctx,
CORBA::Request_ptr
CORBA::Object::_request (const char *operation)
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;
if (this->protocol_proxy_)
{
TAO_Dynamic_Adapter *dynamic_adapter =
Expand Down Expand Up @@ -475,7 +460,7 @@ CORBA::Object::_request (const char *operation)
CORBA::Boolean
CORBA::Object::_non_existent ()
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;

CORBA::Boolean retval = false;

Expand All @@ -496,22 +481,22 @@ CORBA::Object::_non_existent ()
CORBA::InterfaceDef_ptr
CORBA::Object::_get_interface ()
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;
return this->proxy_broker ()->_get_interface (this);
}

CORBA::Object_ptr
CORBA::Object::_get_component ()
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;
return this->proxy_broker ()->_get_component (this);
}
#endif

char*
CORBA::Object::_repository_id ()
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;
return this->proxy_broker ()->_repository_id (this);
}

Expand All @@ -528,7 +513,7 @@ CORBA::Object::_repository_id ()
CORBA::Policy_ptr
CORBA::Object::_get_policy (CORBA::PolicyType type)
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;

if (this->protocol_proxy_)
return this->protocol_proxy_->get_policy (type);
Expand All @@ -545,7 +530,7 @@ CORBA::Object::_get_policy (CORBA::PolicyType type)
CORBA::Policy_ptr
CORBA::Object::_get_cached_policy (TAO_Cached_Policy_Type type)
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;

if (this->protocol_proxy_)
return this->protocol_proxy_->get_cached_policy (type);
Expand All @@ -564,7 +549,7 @@ CORBA::Object::_set_policy_overrides (
const CORBA::PolicyList & policies,
CORBA::SetOverrideType set_add)
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;

if (!this->protocol_proxy_)
{
Expand Down Expand Up @@ -606,7 +591,7 @@ CORBA::Object::_set_policy_overrides (
CORBA::PolicyList *
CORBA::Object::_get_policy_overrides (const CORBA::PolicyTypeSeq & types)
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;
if (this->protocol_proxy_)
return this->protocol_proxy_->get_policy_overrides (types);
else
Expand All @@ -623,7 +608,7 @@ CORBA::Boolean
CORBA::Object::_validate_connection (
CORBA::PolicyList_out inconsistent_policies)
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;

inconsistent_policies = nullptr;
CORBA::Boolean retval = true;
Expand Down Expand Up @@ -665,7 +650,7 @@ CORBA::Object::_get_orb ()
}
else
{
TAO_OBJECT_IOR_EVALUATE_RETURN;
TAO_OBJECT_IOR_EVALUATE;
if (this->protocol_proxy_)
return CORBA::ORB::_duplicate (this->protocol_proxy_->orb_core ()->orb ());
else
Expand Down Expand Up @@ -729,8 +714,13 @@ operator<< (TAO_OutputCDR& cdr, const CORBA::Object* x)
/*static*/ void
CORBA::Object::tao_object_initialize (CORBA::Object *obj)
{
CORBA::ULong const profile_count =
obj->ior_->profiles.length ();
// For a local object or when no ior has been set nothing has to be done
if (obj->_is_local () || !obj->ior_)
{
return;
}

CORBA::ULong const profile_count = obj->ior_->profiles.length ();

// Assumption is that after calling this method, folks should test
// for protocol_proxy_ or whatever to make sure that things have
Expand Down Expand Up @@ -825,8 +815,6 @@ CORBA::Object::tao_object_initialize (CORBA::Object *obj)

obj->protocol_proxy_ = objdata;

obj->is_evaluated_ = true;

// Release the contents of the ior to keep memory consumption down.
obj->ior_ = nullptr;

Expand Down
20 changes: 5 additions & 15 deletions TAO/tao/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "tao/Arg_Traits_T.h"
#include "tao/Any_Insert_Policy_T.h"
#include <atomic>
#include <mutex>

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

Expand Down Expand Up @@ -293,9 +294,6 @@ namespace CORBA

#endif /* GEN_OSTREAM_OPS */

/// Accessor to the flag..
CORBA::Boolean is_evaluated () const;

/// Accessor for the ORB_Core..
TAO_ORB_Core *orb_core () const;

Expand Down Expand Up @@ -335,6 +333,10 @@ namespace CORBA
# define TAO_OBJECT_USES_STD_ATOMIC_REFCOUNT
std::atomic<uint32_t> refcount_;

/// once_flag to make sure that this object is only initialized once
std::once_flag object_initialized_flag_;
# define TAO_OBJECT_USES_STD_ONCE_FLAG_OBJECT_INITIALIZED

private:
Object (const Object &) = delete;
Object &operator = (const Object &) = delete;
Expand All @@ -343,9 +345,6 @@ namespace CORBA
/// Specify whether this is a local object or not.
CORBA::Boolean is_local_;

/// Flag to indicate whether the IOP::IOR has been evaluated fully.
CORBA::Boolean is_evaluated_;

/// If the IOR hasnt been evaluated fully, then the contents of
/// the IOR that we received should be in here!
IOP::IOR_var ior_;
Expand All @@ -372,15 +371,6 @@ namespace CORBA
* Objects
*/
TAO_Stub * protocol_proxy_;

/// 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.
*/
TAO_SYNCH_MUTEX object_init_lock_;
};
} // End CORBA namespace.

Expand Down
7 changes: 0 additions & 7 deletions TAO/tao/Object.inl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ ACE_INLINE
CORBA::Object::Object (int)
: refcount_ (1),
is_local_ (true),
is_evaluated_ (true),
ior_ (),
orb_core_ (nullptr),
protocol_proxy_ (nullptr)
Expand Down Expand Up @@ -56,12 +55,6 @@ CORBA::Object::_narrow (CORBA::Object_ptr obj)
return CORBA::Object::_duplicate (obj);
}

ACE_INLINE CORBA::Boolean
CORBA::Object::is_evaluated () const
{
return this->is_evaluated_;
}

ACE_INLINE TAO_ORB_Core *
CORBA::Object::orb_core () const
{
Expand Down

0 comments on commit b00bd29

Please sign in to comment.